Cobertura for J2ME

Coverage tool for the Java(™) ME platform


Frequently Asked Questions

The traditional FAQ section:


How do I use Cobertura for J2ME included build script

You need to edit the file cobertura4j2me.properties that you can find in the installation directory. Here's a list of the properties to edit:
  • path.instrumented the output directory after instrumentation (default value is ${cobertura4j2me.path}/instrumented-classes)
  • path.report the directory where the report gets generated (default value is ${cobertura4j2me.path}/report)
  • path.data.instr the (generated) instrumentation data file path (default value is ${cobertura4j2me.path}/${file.data.instr})
  • path.bin this is the directory that contains your compiled code to instrument (default value is ${cobertura4j2me.path}/bin)
  • path.device.data the path on device/emulator of the directory where the instrumentation data file is generated (default value is root1/).
    Note that the path must already exist on the device
topback to top

Intrumenting my code returns the error 'No class to instrument'

This means that the PATTERNS you provided to ant cannot be resolved. Make sure that the paths exist.
Note that it is comma separated and that you should use quotes if more than one pattern.
Example:
ant cobertura4j2me-instrument -Dpattern "mypackage1/*.class,mypackage2/*.class"
topback to top

Why some classes are skipped during instrumentation?

Because they are in fact interfaces and it is not possible to intrument an interface.
Also, the class java.lang.Object cannot be intrumented because it would create cyclic dependencies at runtime.
topback to top

What does N/A mean in the html report?

It means that the coverage data is not available. This is because either the class is an interface or it has been compiled without debug information.
topback to top

Can I get the result of several test suite runs in one single report?

Yes, the merge tool searches for all the *.ser files in the Cobertura for J2ME directory and merges all the data in cobertura.ser. Therefore, if you want the generate a report from different runs you just need to copy all the data files - after renaming them of course - and merge them. Then you can generate the report.
topback to top

Why does the report display 'Source file not found' for some classes?

Have you used the right command? Assuming you did, one of the known limitations of Cobertura for J2ME is that it cannot locate the source file of nested classes, i.e. classes declared in another class file - not to confuse with inner class.
topback to top

I get an OutOfMemoryError when running my test, what can I do?

It is probably because you instrumented too many classes. The solution is either to
  • intrument less classes
  • increase the heap size (if using emulator)
topback to top

I don't get any result after running the test, what can I do?

  1. This could simply mean that the code instrumented hasn't been exercised at all. Make sure that the tests you are running are using the intrumented code.

  2. This could also mean that the code hasn't been correctly instrumented. Reiterate the instrumentation step and check for the following message:
    "!!! No line number information found"
    If printed out, this probably means that the code does not contain debug information so try again to prepare for instrumentation.

  3. If still no success, also make sure that the property path.device.data is correctly set. Check in rutime console for the following message:
    "Error getting the instrumentation data file path"
  4. And finally if your tests run very quickly (under five minute) this also could mean that the "hook" used to save to coverage data on exit did not work. Make sure that your test MIDlet correctly exists (that is the destroyApp() method is invoked). And if running the MIDlet on Sun's Wireless Toolkit it is preferable to run the application in trusted domain in order not to get prompted for accessing the file system. Click here for more information on setting up the security domain.
topback to top

I get a '(!)' in the html report, what does that mean?

This means that you forgot to merge the runtime and instrumentation data. In that case, your report only contains the runtime coverage data and since it does not know which code has been intrumented, all the coverage metrics are 100%.

Simply merge the runtime and instrumentation data and regenerate the report.

topback to top

How do I integrate Cobertura for J2ME with antenna?

Please refer to the sample application section for an example of how to use antenna and Cobertura for J2ME. Basically it requires adding an extra step in the packaging of your application to perform the intrumentation.
topback to top

How do I change the security domain in Sun's Wireless Toolkit?

WTK 2.2 Open the KToolbar and in Preferences select the Security tab and choose the Trusted security domain. Now the next time you run an application it should by default be in the trusted domain.

WTK 2.5/2.5.1 Open the KToolbar and in Preferences select the Security menu and choose the manufacturer security domain. Now the next time you run an application it should by default be in the trusted domain.

topback to top