开发者

Why can we unit-test a GWT Widget without compilation to JavaScript?

Right, I have been developing a application using the MVP framework as reccomended by Google in Large scale application development and MVP.

Everything works fine, I just got one thing that is annoying me a little bit (from a understanding point of view).

In the presenter, the Widget class is used in their examples, in the asWidget methods. How come this doesn't pose a problem when mocking the View and doing JRE-bas开发者_开发技巧ed JUnit tests? Doesn't the base Widget class get compiled into JavaScript?


When you run your tests (without GWTTestCase), they're just plain Java code. GWT doesn't translate anything to JavaScript (only the DevMode, Compiler, or GWTTestCase do so), so the Widget class is the one Eclipse (or whatever) sees and allows you to use in your code.

The cases where a GWTTestCase is required is when you actually run code that requires being translated to JS (or similarly run in a "browser environment" with a JS engine, in the case of DevMode, and GWTTestCase in dev mode), that is, trying to call a JSNI method (which happens to simply be a native method as far as Java is concerned).
As long as you don't try to actually use a Widget, it doesn't need any JSNI, so it's safe.


No it does not during debug or hosted mode that is why you can put a breakpoint in eclipse and see it as well.of course behind the scene JavaScript is there but for user it is just java this mapping is controlled by gwts engine.


You can write your unit test without calling the asWidget or you can provide view that returns null for this call.

So by this you remove the need of JavaScript during run time of Unit tests

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜