Mobile JUnit: Java ME Unit Testing
I’ve been playing around with Mobile JUnit, a great new tool from Sony Ericsson. If you’re a Java SE or EE programmer, you’re probably familiar with the JUnit project, an open source unit testing framework for Java. With JUnit you write simple classes (test cases) that have a number of methods that use assertions to test various aspects of your code:
import com.sonyericsson.junit.framework.*;
public class MyTest extends TestCase {
public void testOnePlusOne(){
assertBoolean( 1 + 1 = 2 );
}
}
You can build entire test suites of test cases and automatically run the tests using test runners that display their results either on the console or in a window (there are runners for AWT and for Swing).
Mobile JUnit is a rewrite of JUnit specifically for CLDC-based platforms. Because JUnit depends on reflection and reflection is not available with the CLDC, Mobile JUnit takes a different approach and gathers testing information at compile time and generating helper classes to actually run the tests. (As a side note, Mobile JUnit is based on JUnit 3.8.1 — later versions of JUnit have dependencies on Java 1.5 features like annotations.) It then compiles everything into a MIDlet and runs the MIDlet in the emulator for you. You can even do on-device testing (for Sony Ericsson phones) if necessary, without having to install the MIDlet on the device — Mobile JUnit takes care of that for you.
Even though Mobile JUnit is from Sony Ericsson and by default assumes you’re using it with the Sony Ericsson SDK for CLDC programming, Mobile JUnit can be used with any tool that is based on Sun’s Wireless Toolkit (WTK). If you’re looking to add some automated testing to your build procedure (Mobile JUnit integrates well with Ant) then check it out.
Technorati Tags: J2ME, Java ME, JUnit, Mobile JUnit, unit testing, testing

























[…] (via Eric Giguere, J2ME expert and author) […]