Sunday, March 15, 2009

Application Version Upgrade in MIDP 2.0 and MIDP 1.0

Hey Readers,

First of all very nice good evening to all of you. I really appreciate your love and interest and special thanks to Rochak sir, who believe in my posts. If there is any mistake in my posts then please guide me; I am trying to share my knowledge with all of my readers and this will continue in future.

Today I am going to share version upgrade for mobile application using J2ME in MIDP 2.0 and MIDP 1.0. Being a developer & entrepreneur you always want how to inform user about the application's version upgrade. Because you don't want to loose your customer and want to facilitate user by application's new features. The solution is as follows:-

As a developer or even as a user, I always wish that if there is any version upgrade then please let me know at the startup of application even before Splash Screen appears. You can implement the version upgrade functionality in startApp() method. Even you can also store current version in the RMS. Take a look at the functionality:-

protected void startApp() throws MIDletStateChangeException {
try {

/**Check the record store for available version.*/

//fetch the latest available version from server and compare with stored version in RMS

if (!versionStored.equals(availableVersion) && optionalUpgrade) {

} else if (!versionStored.equals(availableVersion) && mandatoryUpgrade) {

} else if(versionStored.equals(availableVersion)) {

catch(RecordStoreException rse) {
//If application is fresh installation then at startup you'll receive the RecordStoreException, because no record store available.

/** Open record store and store current version of MIDlet. */


Now you are thinking what is the purpose of optionalApplicationUpgrade() and mandatoryApplicationUpgrade(); Both of these functions are very useful. Consider a scenario in which you update only the themes for application but it is not mandatory update because there is no functionality upgrade, in this scenario you can use optionalApplicationUpgrade() and ask user to allow upgrade. But user can may be skip this upgrade; whereas in functionality upgrade you can use mandatoryApplicationUpgrade() and user can't skip this upgrade.

Till now we setup all the basic architecture for application upgrade, but how we are going to upgrade this is the basic query in your mind. Let's resolve that:-

protected void updateApplication() {

if (profile == MIDP2.0) {

String applicationUpdateURL =;


/** Store the updated version of application in RMS */

} else if(profile == MIDP1.0) {

/** Display information to the user for manually upgrade application or you can also send information to the application server to send a WAP push message. */



Using updateApplication() method you can handle functionality for both MIDP1.0 and MIDP2.0, because platformRequest() method is not supported in MIDP1.0; so either you display the information to user or you can push the wap push message to user by sending a specific format message to the OTA server.

This is all about J2ME application upgrade, If I miss something or you have any doubt then please let me know. I'll try my best to explain each of your queries.

Saturday, March 7, 2009

J2ME & Unit Testing

Hi Friends,

As you came to know from the blog title that today we are going to discuss about unit testing approach for J2ME. Before moving further, let's first understand unit testing. Most of the Mobile Application developer think that unit testing is same as the functionality testing which is not true. Functionality testing comes in picture when application installed on mobile and then we test the proper functionality of the application as per the product specification; where as unit testing comes in picture at your code level. In simple words, Unit Testing is an approach that provides confidence to the developer that given piece of code written by him/her are fit for use.

To support unit testing in JAVA we have JUnit Framework, we cannot use same framework for J2ME because JUnit rely on Java Reflection API whereas reflection API is not part of J2ME environment. So there is refine version of JUnit for mobile application unit testing. Actually there are two:
a) J2MEUnit
b) JMUnit
Both are Open Source and used for unit testing approach, but JMUnit has better approach for same. JMUnit has rich set of assert methods as compared to J2MEUnit. In future there are planning to merge these two frameworks into one & emerging framework will have the features of both.

My Experience with JMUnit:-
I used JMUnit in our project and trying to share my experience with all of you. You can use ANT task for running your unit tests. The basic approach for unit testing is that write test cases for those classes which internally call other class's methods, so that you need not to write test cases twice. For example, You can write test cases for one class that manage all the UI related functionality, second that manage RMS related functionality, third that manages data objects, fourth that manage HTTP/HTTPS connections, and the last one is your request and response objects. Suppose you have some abc() method in any class then you should write your testclass with method name testAbc() and test your code scenario as per the requirement. The basic architecture of test class is as follows:

First you have two import JMUnit APIs according to the CLDC
i) jmunit.framework.cldc10.*; //or
ii) jmunit.framework.cldc11.*;

Now basic skelton of a class--

public class Xyz extends Testcase {
public Xyz() {
super(int totalTests, String xyzTest);
public void setUp() {
// define any object or any initialization as per your requirement.
public tearDown() {
// release memory.
public void testAbc() {
// write your test case
public void test(int testNumber) throws Throwable {
switch(testNumber) {
case 0:
When you write all the test cases for your defined classes then you can combine them to in a TestSuite class so that each test will run using your ant script. The architecture for TestSuite class is as follows:

public class AbcTestSuite extends TestSuite {
public AbcTestSuite() {
super("Test Suite");
add(new Xyz);
add(new .......);
Now in the ant script you have to map the JMUnit jar files and you can also specify your test classes, source and reports directory path so that each will move to there respective folder and at the end html based reports will get generated.

1) I am not able to test the RMS value.
2) Also not able to test the UI Classes screen transition.
As per their documentation, I am able to run emulator from ant script but still not able to test both of them. If someone earlier also faced this problem and got any solution.... Please let me know.

I tried to share all the facts related to mobile application testing using JMUnit. If I forgot something please update me with your comments.