Francisco Benitez Leon's Blog

September 22, 2009

Giving a hand with JMUnit

Filed under: Mobility — Tags: , — Francisco Benitez Leon @ 7:46 pm

I don’t know why I haven’t blogged on this before but that’s it, I was added as a developer of the JMUnit project three weeks ago. I posted in the JMUnit forum about the patch I made to avoid the TestSuite execution problem and four days after I was discussing JMUnit 2 features with Carl A. Meijer (one of the administrators of JMUnit). Carl was kind enough to contact me, suggest me how to enhance the patch runners and include me as a member of the project. Not only I am enjoying working on JMUnit but I am also learning a lot in the process. Thank you Carl!

JMUnit 2 looks promising and JMUnit 1 users will love the new release. It will include new features, solve known problems, as the TestSuite execution one, be more convenient to use and, besides that, porting your old tests will be plain and simple. The code is almost finished and the delay in releasing it will lie in the proof-of-concept plug-ins we want to include for Eclipse and NetBeans.

Hopefully, you will be able to use JMUnit 2 soon.


August 15, 2009

Revisiting JMUnit, JMUnit Revised 2.0

Filed under: Java ME — Tags: , , , — 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 patch, I tried to integrate it into NetBeans hacking the mobility pack to get the patched library working with the mobility wizards for creating unit tests. However, due to the design of the patched sources it was impossible to achieve. I also detected a problem with the design that was preventing TestSuite from creating the TestCases read from the Application descriptor (I have never used the custom property JMUnitTestClasses since I started using the modified JMUnit sources).

Based on the general idea of eliminating MIDlet from the inheritance chain I have redesigned the patch, instead of passing a MIDlet to Test in its constructor, Test has to be initialized with a MIDlet before creating any Test object (TestCase, TestSuite or TestRunner). The new desing doesn’t break any of the features of JMUnit, its usage is much simpler  and it can be almost fully integrated in NetBeans, as I will explain next week.

You could download the patch and know more of this new release at JMUnit Revised 2.0.

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! 😉

Create a free website or blog at