单元测试如何使用SmartGWT类? [英] How can unit-tests use SmartGWT classes?

查看:113
本文介绍了单元测试如何使用SmartGWT类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在SmartGWT Web应用程序中,我们将域对象从服务器传递到客户端,然后再传递回客户端(通过GWT序列化).要在DynamicForm或GridList的客户端显示/编辑数据,我们必须将其转换为 ListGridRecord ),然后再编辑回我们的域对象.

In our SmartGWT web application, we pass our domain objects from the server to the client and back (via GWT serialization). To show/edit the data at client side in a DynamicForm or a GridList, we have to convert it into a Record (or ListGridRecord) and after editing back into our domain objects.

我想为此转换方法编写单元测试,但由于记录的

I would like to write a unit test for this conversion method, but a straightforward attempt in JUnit fails, since the record's getAttribute and setAttribute methods are implemented by JSOHelper.getAttribute/JSOHelper.setAttribute, which are static methods declared as native and implemented by JSNI in JavaScript, thus only usable on the client side, when compiled to JavaScript.

在JUnit中使用这些方法时,由于未在其中实现本机方法,因此会收到UnsatisfiedLinkError.

We get an UnsatisfiedLinkError when using these methods from JUnit, as the native methods are not implemented there.

有什么想法可以测试这些课程吗?

这些关键方法可以通过简单的HashMap(或者如果属性顺序很重要,则可以是LinkedHashMap)轻松实现-实际上,如果仅查看数据部分而不是方法,则JavaScript对象就是关于此的.因此,我只是考虑为某些选定的SmartGWT类(主要是JSOHelper)提供Java实现而不是JavaScript实现的替代实现.

These critical methods could be easily implemented by a simple HashMap (or maybe a LinkedHashMap, if the attribute order is important) - actually a JavaScript object is about that, if only looking at the data part, not the methods. Thus I just think about providing an alternative implementation of some selected SmartGWT classes (mainly JSOHelper) with Java implementations instead of the JavaScript ones.

但是我真的是第一个遇到这个问题的人吗?我只是太愚蠢而找不到现有的解决方案吗?

But am I really the first one who has this problem? Am I simply too stupid to find the existing solution?

推荐答案

如果您在代码中使用了MVP或MVC模式,则只需使用 Selinium 之类的东西,我认为gwtTestCase不能与smartGWT一起使用.只是围绕着js代码的gwt包装器.

If you have used a MVP or MVC pattern in your code, just mock the view code with something like mockito and test all the rest of the application. To test the view code you will need to use something like Selinium I don't think gwtTestCase would work with smartGWT since it is just a gwt wrapper around js code.

这篇关于单元测试如何使用SmartGWT类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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