How can unit-tests use SmartGWT classes?

非 Y 不嫁゛ 提交于 2019-12-11 12:08:39

问题


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.

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

Any ideas how I could test these classes?

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?


回答1:


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.



来源:https://stackoverflow.com/questions/9538482/how-can-unit-tests-use-smartgwt-classes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!