Thursday, October 22, 2009

Netbeans and GWTTestCase

In the "yet another problem I couldn't find an answer on Google for" unofficial series.

The problem lies in the fact that the GWT compiler operates on Java source code and not Java bytecode. Unfortunately, a standard WAR project on Netbeans will exclude the Java sources from a WAR file.

The first step is to go edit your project and go to "Build" and in "Exclude From WAR File:" (their spelling here not mine) field remove the value there which by default is "**/*.java,**/*.form".

The second thing you need to do is go to the run section and specify heap options in the "VM options" field. This is needed because tests run outside the application server you're using.

Finally, just hit "Test Project" and see your GWTTestCase's go. However, I would be remiss if I didn't mention that the vast majority of your GWT test code should not use GWTTestCase. Simply put, if your views are properly segregated, the majority of your GWT client code will run as regular Java code, so just use regular JUnit test cases for those.

No comments: