Friday, September 10, 2010

Unit Testing for J2ME - JMUnit

In professional development environment it is a common practice to create Unit Tests. On Java platform there are lots of research and development done on Unit Tests for Enterprise Edition. As far as Java Micro Edition is concerned one of the framework available is JMUnit.

Creating and executing a test case using jmunit is quite simple and can be done without wasting much time to explore it. Following steps will guide you how to work with jmunit:

  •  In your mobile application right click on package (where you want to create a unit test) and select option 'New > Empty JMUnit Test'.
  • It will create a unit test class for you that will look like this:
    /*
     * ABCTest.java
     * JMUnit based test
     *
     */
    
    package hello;
    
    
    import jmunit.framework.cldc10.*;
    
    /**
     * @author rizwan
     */
    public class ABCTest extends TestCase {
        
        public ABCTest() {
            //The first parameter of inherited constructor is the number of test cases
            super(0,"ABCTest");
        }            
    
        public void test(int testNumber) throws Throwable {
        }    
    }  

    • Next you will create a test method in same class and call it in test() using switch cases.
    • Total count of test cases will also be mentioned in unit class constructor.
    • Now the code will look like this:

    /*
     * ABCTest.java
     * JMUnit based test
     *
     */
    
    package hello;
    
    
    import jmunit.framework.cldc10.*;
    
    /**
     * @author rizwan
     */
    public class ABCTest extends TestCase {
        
        public ABCTest() {
            //The first parameter of inherited constructor is the number of test cases
            super(1,"ABCTest");
        }            
    
        public void test(int testNumber) throws Throwable {
            switch(testNumber){
                case 0: 
                    testOne();
                    break;
            }
        }    
    
        private void testOne() throws Exception{
            String tmp = "Hello Rizwan";
            assertEquals(tmp, "Hello Rizwan");
        }
    } 

    • After that you have to mention 'ABCTest' as your Midlet.
    • Go into 'project properties > Application Descriptor > MIDlets' and define unit test name and package here.
    • Run application and you will also get Test option on screen:  
    • Test the project and it will show you the results




    Your mobile test case is ready !

    rizzz86

    Saturday, September 4, 2010

    Open Transport Tycoon Deluxe (TTD)

    TTD is one of my most favorite games that I have played and when I saw the 'Open' with it, I was really excited to install it on my Ubuntu OS.

    The installation of Open TTD is difficult and you need to be a bit keera of shell scripting to do this job. I have followed all the steps on this link and managed to install OTTD successfully. After completing installation and launching the game I was really amazed by watching the same TTD main screen as what I was playing on my 'Windows OS' four years back.


    The game is upgraded now and contains four different types of maps with each map containing different industries, disasters, vehicles etc. Maps are also really interesting with environment like a Desert area map, Snow area map, Toyland area map and a default one as well. I have some getty images of the game that are as follows:


    All TTD lovers do enjoy this on your Linux OS.

    rizzz86

    Friday, September 3, 2010

    Amir, Asif & Salman - From Hero to Zero


    Pakistani cricketers are again under a controversy and this time it is a serious one - the FIXING case :|

    The trio who are Hero of last week are now Zero. In my last blog I am really excited of Pakistan's fighting win over England and now I am not much interested to even watch a cricket match.

    Is it a non-professionalism or a trap or anything else - the trio-players has taken part in this show of money. The future of these players is still not clear and are at stake. But as a Pakistani I am still hoping these players will not have a life ban and will play cricket after completing their punishments.

    rizzz86