J2ME Specifics

Component Testing for Java

Component Testing for Java supports the Java 2 Platform Micro Edition (J2ME) through a specialized version of the JUnit testing framework.

This framework requires that you manually perform the two following additional steps:

  1. Create a test suite class Suite() that transforms a test class into a J2ME test suite.

  2. Create a runTest() primitive that transforms the name of the test case into a relevant call to the test function.

The objects under test must belong to the test class and must have been initialized in the setUp method.

The following code sample is a runTest selection method for J2ME, which switches the correct test method depending on the name of the test case:

protected void runTest() throws java.lang.Throwable {

if(getTestMethodName().equals("testOne"))

                       testOne();

else if(getTestMethodName ().equals("testTwo"))

testTwo();

}

Building a Test Suite

The two following methods demonstrate how to build a test suite from a J2ME test case.

public Test suite() {

return new TestSuite(new TestOne().getClass(),new String[] {"testOne"});

}

 

 

public static Test suite() {

TestSuite suite = new TestSuite();

suite.addTest(new TestMine().suite());

suite.addTest(new TestMine2().suite());

return suite;

}

 

Integration of Objects Under Test

The objects under test must belong to the test class and must have been initialized in the setUp method.

Related Topics

Java Test HarnessJava Stubs