This section will explain how to configure the Cobertura Ant task in your project.
The following are the steps for configuration:
Chapter05lib
. Include all JARs from the lib
folder and cobertura.jar
from the root
folder.build.properties
file under Chapter05Chapter05
and enter the following information:src.dir=src/main/java test.dir=src/test/java # The path to cobertura.jar cobertura.dir=../lib classes.dir=classes instrumented.dir=instrumented reports.dir=reports # Unit test reports from JUnit are deposited into this directory reports.xml.dir=${reports.dir}/junit-xml reports.html.dir=${reports.dir}/junit-html coverage.xml.dir=${reports.dir}/cobertura-xml coverage.summaryxml.dir=${reports.dir}/cobertura-summary-xml coverage.html.dir=${reports.dir}/cobertura-html
The src.dir
attribute represents the source folder location and test.dir
represents the test file location. The cobertura.dir
attribute refers to the Cobertura library or JAR files. The coverage tool needs to access the Cobertura library files. The other entries are required for report generation and bytecode instrumentation.
build.xml
file under Chapter05Chapter05
, and add targets for Cobertura instrumentation and JUnit test to update the .ser
file and generate the report. Download the build.xml
file from the Packt Publishing website (the Chapter05
code). The important targets are init
, compile
, testcompile
, instrument
, test
, coverage-report
, summary-coverage-report
, alternate-coverage-report
, and clean
.Chapter05Chapter05
, and issue the ant
command. This will generate the report. The following is the console output of the command:Cobertura generates the report in Chapter05Chapter05
eports
. The reports
folder contains various reports in XML and HTML formats.