Cobertura for J2ME

Coverage tool for the Java(™) ME platform


Ant Tasks

This section gives an overview of the ant tasks provided with Cobertura for J2ME. First, we describe how to setup your ant build script and then we look at each task in details:

Setup your build script

The first thing you need to do in order to use the following ant tasks is to import the tasks in your project. This can be achieved by simply importing the tasks definitions:
<!-- import Cobertura for J2ME tasks --> <taskdef resource="cobertura4j2me-tasks.properties" classpath="${cobertura4j2me.path}/cobertura4j2me.jar">
where ${cobertura4j2me.path} references your Cobertura for J2ME installation directory.
topback to top

cobertura4j2me-intrument

Parameter Required? Description Default Value
datafile No Specify the name of the file to use for storing the metadata about your classes. This is a single file containing serialized Java classes. It contains information about the names of classes in your project, their method names, line numbers, etc. It will then be used to merge with your runtime coverage data and generate the coverage report. cobertura-instr.ser in current directory
keepdata No Indicates whether the datafile should be overwritten if it already exists. If set to true the metadata of new classes to intrument will be appended to the existing file. false
todir No Specify the output directory for the instrumented classes. Note: If you do not specify a todir attribute, be careful to make sure to delete any instrumented class files whenever you delete your cobertura-instr.ser file. If no destination directory is specified, then the uninstrumented classes will be overwritten with their instrumented counterparts.
devicepath No Specify the path on the device/emulator where the runtime coverage data file is generated. Note that the path must already exist on the device. root1/ (maps to the default directory structure of Sun's Wireless Toolkit.)

You must tell Cobertura for J2ME which class files to instrument by passing in standard ant filesets.

Example:

<cobertura4j2me-instrument todir="instrumented"
                           devicepath="root1/">
    <fileset dir="bin" includes="**/*.class">
</cobertura4j2me-instrument>
topback to top

cobertura4j2me-merge

Parameter Required? Description Default Value
datafile No Specify the name of the output file containing coverage data about your classes after the merge completes. cobertura.ser in current directory

You must tell Cobertura for J2ME which coverage data files to merge by passing in standard ant filesets.

Example:

<cobertura4j2me-merge>
    <fileset dir="${basedir}">
        <include name="**/*.ser" />
    </fileset>
</cobertura4j2me-merge>
topback to top

cobertura4j2me-report

Parameter Required? Description Default Value
format No The type of report you want to generate. Either xml or html. html
datafile No Specify the name of the file containing coverage data about your classes. cobertura.ser in current directory
srcdir Yes Specify the directory containing the source code of your project. This is used to calculate the cyclomatic code complexity of each class. The HTML reports are also made of annotated versions of each source file, showing which lines of code were excercised. No default value
destdir No Specify the output directory for the report. report in current directory
title No Specify the title of the report (html report only). Coverage Report
logo No Specify the path to your project logo. It will be added to the html report only. No default value
copyright No This parameter allows to add a copyright notice at the bottom of the HTML report. If not specified no copyright notice will be added. No default value

Example:

<cobertura4j2me-report title="MyProject Coverage Report"
                       copyright="Copyright (c) 2007 My Company"
                       logo="${basedir}/logo.gif"
                       srcdir="src" />
topback to top

cobertura4j2me-check

Parameter Required? Description Default Value
datafile No Specify the name of the file containing coverage data about your classes. cobertura.ser in current directory
branchrate No Specify the minimum acceptable branch coverage rate needed by each class. This should be an integer value between 0 and 100. 0
linerate No Specify the minimum acceptable line coverage rate needed by each class. This should be an integer value between 0 and 100. 0
packagebranchrate Yes Specify the minimum acceptable branch coverage rate needed by each package. This should be an integer value between 0 and 100. 0
packagelinerate No Specify the minimum acceptable line coverage rate needed by each package. This should be an integer value between 0 and 100. 0
totalbranchrate Yes Specify the minimum acceptable average branch coverage rate needed by the project as a whole. This should be an integer value between 0 and 100. 0
totallinerate No Specify the minimum acceptable average line coverage rate needed by the project as a whole. This should be an integer value between 0 and 100. 0

You can specify finer-grained thresholds for certain classes using regular expressions. See the example below.

Example:

<cobertura4j2me-check branchrate="30"
                      totalbranchrate="60"
                      totallinerate="80">
    <regex pattern="com.mycompany.*" branchrate="80" linerate="90"/>
</cobertura4j2me-check>
topback to top