HOWTO use CodeCover with ANT
This tutorial is about using CodeCover with an Apache ANT script file.
The templates for ANT are the files ant-build-codecover.xml
and ant-build-codecover2.xml
. ant-build-codecover.xml
is a simple example for using CodeCover which instruments, compiles and executes the code and then creates a report.
With ant-build-codecover2.xml
, the compiled code will be executed twice, so two test sessions will be created. A report will be created after the second execution. The application that is used as an example here is called SimpleJavaApp. Its sources are available here, as .zip or .tar.bz2.
In order to use the template files you must adapt their heads to your system.
<property name="codecoverDir" value="codecover"/>
<property name="sourceDir" value="src"/>
<property name="instrumentedSourceDir" value="instrumented"/>
<property name="mainClassName" value="Test"/>
- The property
codecoverDir
must be set to the CodeCover folder (the folder with the subfolderplugins
and thecodecover-core.jar
). - The property
sourceDir
must be set to the folder that contains the java source files. - The property
instrumentedSourceDir
must be set to the folder which contains the instrumented source code files and the compiled files. The default value for this property should work in most cases. - The value of the property
mainClassName
must be set to the name of the class that will be executed.
Example: CodeCover is located in the folder /usr/local/share/java/codecover
. The ANT file is called build-codecover.xml
and lies in the SimpleJavaApp folder. The SimpleJavaApp folder contains the source code files in a subfolder called src
. The main class is called SimpleJavaApp.java
.
The head of the ANT file should be modified to look like this:
<property name="codecoverDir" value="/usr/local/share/java/codecover"/>
<property name="sourceDir" value="src"/>
<property name="instrumentedSourceDir" value="instrumented"/>
<property name="mainClassName" value="SimpleJavaApp.java"/>
After these preparations, the script can be used with the command ant -f build-codecover.xml
.