Testing GWT App with Junit GWTTestCase
Before starting I had to to download the jar of JUnit which helps test GWT apps. Download JUnit archive
from JUnit Official Site: http://www.junit.org (Download JUnit-4.10.jar).
GWT provides GWTTestCase base class which provides JUnit integration. Running a compiled
class which extends GWTTestCase under JUnit launches, the
GWTTestCase is a derived class from JUnit's TestCase and it can be run using JUnit Test runner.
Let's demonstrate it with a simple class
Let's demonstrate it with a simple class
/**
* GWT JUnit tests must extend GWTTestCase.
*/
public class WaterTalkTest extends GWTTestCase{
/**
* must refer to a valid module that sources this class.
*/
public String getModuleName(){
return"com.water.talks.WaterTalk";
}
public void testMethodName(){
/**
* tests the FieldVerifier.
* test functionality of composite components
* test service calls and verify it with the result values
* use assert method to
show separation in test results by success and failure categorizations.
*
*/
}
}
Run test cases in Eclipse using generated
launch configurations.
We'll run unit tests in Eclipse using the launch configurations generated by webAppCreator for
both development mode and production mode.
RUN THE JUNIT TEST IN DEVELOPMENT MODE
- From the Eclipse menu bar, select Run > Run Configurations...
- Under JUnit section, select WaterTalkTest-dev, the class u need to run to test the app
- To save the changes to the Arguments, press Apply
- To run the test, press Run
If everything is fine with your application, this will produce result.
RUN THE JUNIT TEST IN PRODUCTION MODE.
- From the Eclipse menu bar, select Run > Run Configurations...
- Under JUnit section, select WaterTalkTest-prod
- To save the changes to the Arguments, press Apply
- To run the test, press Run
If everything is fine with your application, this will produce result:
Thank you for spending time on this post, hope you got some queries regarding this.
No comments:
Post a Comment