Sunday, February 26, 2012

JInjector - J2ME Instrumentation testing


JInjector is an Instrumentation tool for Java Mobile Applications. 

J2ME applications consist of having a pair of files: the JAR and JAD. JAR file containing all the code and resources and JAD file is a text based containing execution parameters. The Deployment is J2ME applications as these tend to include code optimization and obfuscation, together with signing also.

Here the JInjector applies the Instrumentation and resulting classes are pre-verified and packaged together a specific device. But the Initial jar file should not obfuscated (or) optimized. The whole process and the testable code must be preverified again and The JAD descriptor file needs updating with the new JAR size. It instruments the system under test (SUT) in order to run automated tests in emulators and on the actual devices and It can also supports for code coverage.

Below the sample screenshot for the overall architecture



How to instrument LCDUI
LCDUI has strong has encapsulation and those classes cannot be instrumented. Because they are not part of the JDK. For Java Reflection They have done Java byte code conversion - a general purpose instrumentation tool based ASM

The Java ME code:
                        Form form=new Form();
                        form.addCommand(command1);
            Will be instrumented as
                        Form form=new FormWrapper()
                        Form.addCommand(Command1);

Here some of wrapper classes below
Alert- Alert wrapper, Canvas-Canvas Wrapper, Form – Form Wrapper, .. etc

And Wrapper classes have methods like as ……
getTitle();  getCommand(); getAllCommands(); commandListner(); .. etc

Simple test case using wrapper class methods
FormWrapper myForm = (FormWrapper) myScreen;
  assertEquals("The form title should be Sign in","Signin“,myForm.getTitle());
  Command c[]=myForm.getAllCommands();

A Test Method
Package com.reddyapp.test.auth.register;
import com.reddyapp.j2me.JInTestCase;
public class TestHelloMIDlet extends J2meTestCase {
                        public void testRegisterForm (){
                        }
}

Test case Asserts
public void testRegisterForm (){
assertEquals("The form title should be Reddy, “Reddy“, mainForm.getTitle());
}

Test Reporting and Test Results



No comments:

Post a Comment