Search code examples
javagwtjunitgwttestcase

Sharing JUnit tests between client and server


Hello fantastic people!

I am developing a java module which will be used both on the server, and on the client (GWT).

I want to write a library of unit tests, and then simply create wrappers to run the tests on the client and on the server. This way, I can gurentee that the code behaves correctly on both, without having to write separate unit tests for each.

However, I see that there is no native support for JUnit in GWT and that GWTTestCase has to be used.

I was hoping someone might have a clever solution that would allow me to do this.

Thanks,

Casey


Solution

  • If your GWTTestCase returns null from getModuleName(), it'll be run as a simple JUnit test. The idea is thus to have 2 classes, one extending the other and overriding getModuleName().

    FYI, this is the exact technique used by GWT itself in its unit-tests; for instance for RequestFactory or AutoBeans; for instance RequestFactoryTest which extends GWTTestCase and RequestFactoryJreTest which extends RequestFactoryTest, overriding getModuleName() to return null as well as the way the tests are setup.