GWT:单元测试/模拟JSNI方法的最佳实践? [英] GWT: Best practice for unit testing / mocking JSNI methods?

查看:131
本文介绍了GWT:单元测试/模拟JSNI方法的最佳实践?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 受保护的原生JsArray< JsonModel> getModels()/ *  -  {
返回$ wnd.jsonData;
} - * /;

调用此方法,然后将数据翻译并以不同的方法处理。我应该怎么测试这个类,因为我无法实例化(或看似模拟?)JsArray?



单元测试JSNI方法的最佳方法是什么?所有?

解决方案

界面方法是最好的方法,并不一定是矫枉过正。至于实际测试方法的问题 - 好吧,如果它只是从$ wnd.jsonData中读取,那么测试方法没有任何优点。你最好写一个服务器端测试,确认你在主机页面有正确的数据。



如果你真的有一些本地方法的逻辑,你最好关闭写一个硒/ jsunit测试用例。

I have a class which uses JSNI to retrieve JSON data stored in the host page:

protected native JsArray<JsonModel> getModels() /*-{
    return $wnd.jsonData;
}-*/;

This method is called, and the data is then translated and process in a different method. How should I unit test this class, since I'm not able to instantiate (or seemingly mock?) JsArray?

What is the best way to unit test JSNI methods at all?

解决方案

The interface approach is the best approach, and not necessarily an overkill. As to the problem of actually testing the method - well, if it is just reading from $wnd.jsonData, there isn't any merit in testing the method. You are better off writing a server side test that confirms you have the right data in the host page.

If you really have some logic in a native method, you are better off writing a selenium/jsunit test case.

这篇关于GWT:单元测试/模拟JSNI方法的最佳实践?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆