Francisco Benitez Leon's Blog

August 4, 2009

Surpassing JMUnit CLDC 1.1 TestSuite execution barrier on real devices

Filed under: Java ME, Mobility — Tags: , , , — Francisco Benitez Leon @ 8:07 pm

If you have developed Java ME mobile applications and you have used JMUnit for unit testing (which I strongly recommend), you would probably have noticed that TestSuites can’t be executed on some real devices (as Nokia® or Motorola® mobiles) and simulators/emulators (as Symbian 3rd Editon FP1 and FP2 or Java ME SDK) . This is due to the fact that MIDlets can’t create other MIDlets for security reasons (as stated in JSR118 only the application management software can do this), so if you try it you will get a SecurityException.

As explained in JMUnit manual section 3.1, the problem is that TestCase and TestSuite extends Test, which extends Assertion, which extends MIDlet =). So with any TestCase that you add to your TestSuite (which is already a MIDlet) you are adding another MIDlet and that’s why you would get a SecurityException when executing your TestSuite. To avoid this you will have to modify JMUnit source code and break this inheritance chain.

Breaking JMUnit inheritance chain (MIDlet dependency)

The process to break the chain is really easy: eliminate MIDlet from the inheritance chain, pass a MIDlet reference (midletRef) to whichever classes that use MIDlet’s methods and substitute these methods invocations for midletRef.method(). There’s one step more after breaking the chain as there is another class that uses MIDlet via Test, GuiListener has to be modified too.

I have complete this process in a project called JMUnit Revised. You could take a deep look at the process followed to modify JMUnit1.2.1 CLDC1.1 sources, download a patch and consult the usage at JMUnit Revised project’s page at my personal site. After creating a jar with the patched JMUnit1.2.1 CLDC1.1 sources and following the usage instructions you will be able to run your TestSuites on most real devices and simulators/emulators.

Now keep up happy testing! 😉


1 Comment »

  1. […] JMUnit Revised, Testing — Francisco Benitez Leon @ 8:04 pm Some days ago I published a post introducing a patch for JMUnit that I use for being able to execute TestSuites. After releasing the […]

    Pingback by Revisiting JMUnit, JMUnit Revised 2.0 « Francisco Benitez Leon's Blog — August 15, 2009 @ 8:05 pm

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at

%d bloggers like this: