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.
Example pom.xml show test classes bytecode instrumentation. To see how to build compleate MIDLet application see j2me-maven-plugin
<dependencies>
<dependency>
<groupId>com.pyx4me</groupId>
<artifactId>cldcunit</artifactId>
<version>2.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.pyx4me</groupId>
<artifactId>cldcunit-se</artifactId>
<version>2.0.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>net.sf.jour</groupId>
<artifactId>jour-maven-plugin</artifactId>
<version>2.0.1</version>
<executions>
<execution>
<phase>test-compile</phase>
<goals>
<goal>instrument</goal>
</goals>
<configuration>
<jourConfig>${basedir}/process-test-classes.jour.xml</jourConfig>
<classesDirectory>${project.build.testOutputDirectory}</classesDirectory>
<output>test-classes</output>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.pyx4me</groupId>
<artifactId>cldcunit-instrument</artifactId>
<version>2.0.2</version>
</dependency>
</dependencies>
</plugin>
</plugins>
...process-test-classes.jour.xml
<jour>
<aspect descr="TestCaseReflectionData" type="com.pyx4me.cldcunit.TestCaseReflectionDataInstrumentor" enabled="true">
<typedef>*.Test*;Test*</typedef>
<pointcut expr="* test*()"/>
<pointcut expr="junit.framework.Test suite()"/>
</aspect>
</jour>If the only instrumentation required is UnitTests instrumentation use cldcunit.jour.xml included in cldcunit-instrument.jar
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 INSTR_CLASSPATH=%INSTR_CLASSPATH%;javassist.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%