Using CLDC Unit

CLDCUnit can be used as original JUnit when rinning tests with Java J2SE. Simply create regular JUnit test and run in Eclipse or Maven.

When you need to tests on J2ME Device you need to add CLDCUnit jar to your application and create TestRunner MIDLet that will list the tests you want to run. TODO create MIDLet during build to list all tests.

public class UnitTestsMIDLet extends cldcunit.runner.TestRunner {

        protected void startApp() throws MIDletStateChangeException {
                start(new TestCase[] {new TestCaseOne(), new TestCaseTwo()});


Because Java 2 Micro Edition (J2ME) dos not have reflection API we need to add aditional step to build process that will create reflection data. We do this using bytecode instrumentation during build of the MIDlet.

See example project cldcunit-examples

To run the tests in Java 2 Platform Standard Edition (J2SE) bytecode instrumentation is not required. You just need to add cldcunit-se to classpath that runs tests using reflection.

Build and test in maven

Example pom.xml show test classes bytecode instrumentation. To see how to build compleate MIDLet application see j2me-maven-plugin










    <aspect descr="TestCaseReflectionData" type="com.pyx4me.cldcunit.TestCaseReflectionDataInstrumentor" enabled="true">
        <pointcut expr="* test*()"/>
        <pointcut expr="junit.framework.Test suite()"/>

If the only instrumentation required is UnitTests instrumentation use cldcunit.jour.xml included in cldcunit-instrument.jar

Bytecode instrumentation from command line

Download cldcunit libraries from download

All command line options are explained on Jour website

set INSTR_CLASSPATH=jour-instrument.jar
set INSTR_CLASSPATH=%INSTR_CLASSPATH%;cldcunit-instrument.jar

set ME2_HOME=C:\apps\microemulator-2.0.2-SNAPSHOT

set APP_CLASSPATH=cldcunit.jar
set APP_CLASSPATH=%APP_CLASSPATH%;%ME2_HOME%\lib\cldcapi11.jar
set APP_CLASSPATH=%APP_CLASSPATH%;%ME2_HOME%\lib\midpapi20.jar

java -cp %INSTR_CLASSPATH% net.sf.jour.PreProcessor --config process-test-classes.jour.xml --src target\test-classes --dst target\test-classes-instr --classpath %APP_CLASSPATH%