|Figure 7. Generate a JMUnit Test Case Class: NetBeans Mobility Pack 5.5 offers developers a simple menu option to create JMUnit CLDC 1.0 test case classes for any mobile application class.|
While both JMUnit and J2MEUnit can be used with just about any Java ME development environment or IDE like Sun's Wireless Took Kit, one IDE will soon release incorporated copies of these micro edition unit testing tools in its offering. NetBeans 5.5/NetBeans Mobility Pack 5.5 will ship with both of these tools. In fact, NetBeans will automatically generate JMUnit CLDC 1.0 tests for any J2ME project class. Simply right click on any class of Mobile project and ask to generate JUnit test classes from the Tools menu option (see Figure 7).
By default, NetBeans generates JMUnit CLDC 1.0 test cases. You can use a project's properties dialog window to add the JMUnit CLDC 1.1 or J2MEUnit library to the project and then manually create test classes and MIDlet test case runners of any type (see Figure 8).
|Figure 8. Adding Libraries to a Project: NetBeans Mobility Pack 5.5 offers developers a simple menu option to create JMUnit CLDC 1.0 test case classes for any mobile application class.|
To add either the JMUnit CLDC 1.1 or J2MEUnit libraries to a mobile project in NetBeans 5.5, right click on a project and select properties. On the subsequent window, select Build>Libraries and Resources as shown in the figure and then hit the Add Library button to select the other JUnit libraries for use in your project.
According to members of the NetBeans project team, NetBeans 5.5 and NetBeans Mobility Pack 5.5 are expected to be released in late October. A Q-build release of both (with the Java ME unit testing frameworks) is available here.
The download files attached to this article not only contain all the classes demonstrated in this article, they also include NetBeans 5.5 projects that can be quickly and easily brought in to the new NetBeans IDE for exploration. Conversion 1.0 is a project that includes CLDC 1.0 version of the code examples along with JMUnit for CLDC 1.0 and J2MEUnit test cases. Conversion 1.1 is a project that includes CLDC 1.1 version of the code examples along with JMUnit for CLDC 1.1 test cases.
Future Java ME Unit Testing Looking Bright
No longer do you have the excuse that the quality of your Java Micro Edition application suffers because you don't have proper unit testing tools. JMUnit and J2MEUnit (and their soon to be merged incarnation) can provide valuable quality assurance assistance to micro edition developers.
As you can see, these two frameworks differ in a few areas. Many of the differences between the frameworks lie in the implementation details that are below the API most developers will use. JMUnit tends to provide a more rich set of assertions and may be a little easier to implement while J2MEUnit tends look and act a little more like regular JUnit at the suite level. Both offer some nice features that will hopefully be preserved in the merged product.