开发者

jUnit testing with Google Web Toolkit

开发者 https://www.devze.com 2022-12-16 16:12 出处:网络
I would like to be able to run a set of unit tests by linking to them in my application (e.g. I want to be able to click on a link and have it run a set of jUnit tests).The problem is that GWT and jUn

I would like to be able to run a set of unit tests by linking to them in my application (e.g. I want to be able to click on a link and have it run a set of jUnit tests). The problem is that GWT and jUnit don't seem to be designed for this capability -- only at build time can you run the tests it seems.

I would like to be able to include my test code in my application and, from onModuleLoad for example, run a set of tests.

I tried to just instantiate a test object:

StockWatcherTest tester = new StockWatcherTest();
tester.testSimple();

but I get: No source code is available for type com.google.StockWatcher.client.StockWatcherTest; even though I include the module specifically.

Would anyone know a way to do this? I just want to be able to di开发者_高级运维splay the test results within the browser.


If you are trying to test UI elements in GWT using JUnit, unfortunately you may not do so. JUnit testing is limited to RPC and non-UI client-side testing. See this thread for a great discussion on what you can and cannot do with GWT jUnit testing.

If you are not trying to test UI elements, but are instead trying to inject your RPC code or client-side logic with test values (hence why you want to be able to click on a link and run a set of JUnit tests), then you should follow the following guide from testearly.com: Testing GWT with JUnit. In short, you should make sure that the method you are testing does not include any UI elements and if the method you are testing is asynchronous in nature, you must add a timer.

In 2.0, HTMLUnit was added. You may wish to use this instead of firing up a browser each time you wish to test.

0

精彩评论

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

关注公众号