Cobertura for J2ME

Coverage tool for the Java(™) ME platform


Sample Application

This section provides an overview of the sample application shipped with Cobertura for J2ME. Here you will find the necessary information to get your own Java(™) ME project going and be able to get the relevant measurement of your test coverage. Note that this sample application makes use of the great antenna for packaging the MIDlet.

What is this sample application?

The sample application shipped with Cobertura for J2ME provides an illustration of how to mesure the code coverage of an application. By using this project as template you should be able to measure the code coverage of your own project in no time. The build script (build.xml) can be found in the sample directory (see below). Also, refer to the ant tasks section for more details on how to use Cobertura for J2ME ant tasks.

topback to top

Where can I find it?

The sample application can be found in the sample directory of Cobertura for J2ME. So if you installed this tool in C:\APPS\cobertura4j2me-x.y.z you will find the sample application is C:\APPS\cobertura4j2me-x.y.z\sample.

topback to top

How do I build it?

First you need to edit the file build.properties located in the sample directory and update the following property with the location of Sun's Wireless toolkit:

##
# the installation directory of the Wireless Toolkit
wtk.home=C:/APPS/WTK22

Then simply type the following command in a console shell:

ant build

You will then find the files SampleMIDlet.jad and SampleMIDlet.jar in the sample directory. Also, the file cobertura-instr.ser would have been generated in the same location.

topback to top

How do run it?

Once built use Sun's Wireless Toolkit (or any Java(™) ME emulator for that matter) to execute the application. Follow the instructions displayed on the screen and make sure you close the application. After successful completion you will find the generated cobertura.ser file in [WTK_HOME]/appdb/DefaultColorPhone/filesystem/root1 where [WTK_HOME] is your installation directory of Sun's Wireless Toolkit. Copy the file to the root directory of the sample application and you are almost ready to generate the report.

topback to top

How do I generate the report?

At this point you should have the files cobertura-inst.ser and cobertura.ser in the sample application root directory. Only two simple steps are now required to get the html report generated:

  1. Merge the two files by typing the follwing command in your console shell:
    ant merge
  2. And then generate the report:
  3. ant report
Done! The report has been generated in the report directory.

topback to top

How do check minimum coverage?

Once you have merged the instrument and runtime coverage data you can run the cobertura4j2me-check task to verify that the test coverage meets certain minimums. Simply run the following command:

    ant check
it will check the sample application meets the minimum coverage.

topback to top