Friday, March 13, 2009

Creating JUnit test cases for your GWT project

The importance of JUnit testing and benchmarking cannot be undermined for java projects, let alone GWT projects.

Out-of-box JUnit test support is shipped with GWT for client and server side synchronous and asynchronous testing.Each GWT JUnit test extends GWTTestCase and implements getModuleName() method which defines the interest of GWT module.

Hence, if you like to create a project "MyUITest" in eclipse:
Go to your GWT_HOME (the place where your gwt related jars reside) directory and in the command prompt, promptly type in
projectCreator -eclipse MyUITest
and
applicationCreator -eclipse MyUITest -out MyUITest com.rsheyeah.gwt.client.UITest

and the result is as follows:
Created directory MyUITest\src
Created directory MyUITest\src\com\rsheyeah\gwt
Created directory MyUITest\src\com\rsheyeah\gwt\client
Created directory MyUITest\src\com\rsheyeah\gwt\public
Created file MyUITest\src\com\rsheyeah\gwt\UITest.gwt.xml
Created file MyUITest\src\com\rsheyeah\gwt\public\UITest.html
Created file MyUITest\src\com\rsheyeah\gwt\public\UITest.css
Created file MyUITest\src\com\rsheyeah\gwt\client\UITest.java
Created file MyUITest\UITest.launch
Created file MyUITest\UITest-shell.cmd
Created file MyUITest\UITest-compile.cmd

Now heres the line which generates the junit files:

junitCreator -junit "F:\eclipse-jee-ganymede-SR2-win32\plugins\org.junit_3.8.2.v20080602-1318\junit.jar" -module com.rsheyeah.gwt.UITest -eclipse MyUITest com.rsheyeah.gwt.client.UITester

and the result is as follows:
Created directory C:\gwt-windows-1.5.2\test
Created directory C:\gwt-windows-1.5.2\test\com\rsheyeah\gwt\client
Created file C:\gwt-windows-1.5.2\test\com\rsheyeah\gwt\client\UITester.java
Created file C:\gwt-windows-1.5.2\UITester-hosted.launch
Created file C:\gwt-windows-1.5.2\UITester-web.launch
Created file C:\gwt-windows-1.5.2\UITester-hosted.cmd
Created file C:\gwt-windows-1.5.2\UITester-web.cmd

Hence, it is recommended to use GWT JUnit for non-UI based tests, such as logic and functionality tests which may or may not require client and server asynchronous communication.

No comments: