Getting Started with Ant Projects
Last updated
Was this helpful?
Last updated
Was this helpful?
This page guides you through configuring your Ant project to work with Diffblue Cover. Cover needs to understand the structure of the project, and to execute commands and receive feedback from the build system. This is achieved by adding an event spy to produce structured messages and easily add support for additional build systems for Cover.
The diagram below gives an overview of how Diffblue Cover interacts with a build system. The rest of this document walks through how to configure this for an Ant project.
The following is a list of requirements for Diffblue Cover to analyse an Ant project:
The Ant application binary is installed and can be used to build the project on the command line. Instructions for installing Ant are available on the Apache Ant website.
The Diffblue Cover cover-buildsystem-ant-jar-with-dependencies.jar
is available to Ant and added to the classpath. This is available via the Diffblue Maven Repository as well as being distributed in the zip file containing the rest of the Diffblue Cover application.
The artifact can be resolved on the Diffblue Maven Repository using the following details:
URL: https://maven.diffblue.com/release
organisation: com.diffblue.cover
name: cover-buildsystem-ant
version: matches the version of Diffblue Cover you're using, e.g. 2025.02.02
The project is available on your computer and builds without any warnings or errors (i.e. the exit code is zero).
The project is configured to compile test classes (including **/*DiffblueTest.java files)
The project is configured to filter tests by file name from a (series of) command line options (see Test Filtering below)
The project is configured to produce JUnit and JaCoCo XML reports (see Reporting Test Execution and Coverage below)
For JUnit reports, refer to https://ant.apache.org/manual/tasksoverview.html#testing
For JaCoCo XML reports, refer to https://www.eclemma.org/jacoco/trunk/doc/ant.html
The project is configured to generate the structure and event messages (see Reporting the Project Structure and Events)
Diffblue Cover is configured to invoke tasks and command line flags for the different phases (see Configuring Cover to work with your project's build system)
The next parts of this document will describe the configuration using an example project.
For the rest of this guide we will refer to the project outlined below. This is a single module project configured with separated production classes and dependencies from test classes and dependencies. The project has been configured to run tests using JUnit Jupiter (junit5) and measure coverage via JaCoCo reports.
In this example project, we have two production classes in the org.example
package (Basic
and HelloWorld
). There is a single test class BasicTest
which has been configured to run with JUnit Jupiter. In the lib
folder is where the dependencies of the project's build phase live.
The build.xml
has been configured to provide the following targets:
There are a number of properties that are defined (which will become important later on when configuring the project description):
There are also the following classpath entries defined. First, there are two path
s used to group the third-party product and test dependencies (respectively), these are resolved by the resolve
target (defined on line 1) using Ivy to manage the dependencies and put the list in the compile.path
(line 3) and test.path
(line 4) for the different sets of dependencies. The test.classpath
contains the list of test dependencies (line 8), the compiled production classes (derived from src/main
-- line 9), and finally the compiled test classes (derived from src/test
-- line 10):
Before we can configure Cover the project needs to be set up correctly to: measure coverage of any preexisting tests as well as coverage of any newly created tests; report on test successes and/or failures. This ensures the written tests are not going to fail when integrated into the code base.
We will explain the requirements below in turn. The following configuration examples highlight just the necessary parts for illustrative purposes but they must cooperate in a complete project configuration.
During execution of tests we need to differentiate between any preexisting tests and those created by Diffblue Cover, as well as running a single test. By default all the tests created by Diffblue Cover will be placed in files that end in DiffblueTest.java
. This filter needs to be able to be specified via the command line.
An example of a configuration allowing this follows:
In this example, we define two properties: test.includes
(line 1) and test.excludes
(line 2). On the command line, you can then over-ride the include/exclude tests as outlined below:
Only Diffblue tests:
-Dtest.includes=**/*DiffblueTest*
Only Manual tests:
-Dtest.excludes=**/*DiffblueTest*
Named test:
-Dtest.includes=**/DummyDiffblueTest*
By not specifying either of those properties on the command line, all tests (i.e. those with file names containing Test
) will be considered as per the configuration file.
The project must be set up to measure the coverage (taking into account the test filters described above). The JaCoCo Ant Tasks should be configured to produce XML reports. Furthermore, the project must be set up to report on the status of the tests. The JUnit Report Task documentation describes the necessary steps. Diffblue Cover expects that the names of the reports follow the task’s default settings.
The configuration for these follows the respective documentation. An example of the configuration for these two requirements follows:
For Diffblue Cover to process the project structure needs to be passed via a custom task called projectModule
. First we show an example and then describe the purpose and requirements of each of the different options.
This comprises of four steps:
Add Cover to the name space (there may be other namespaces and attributes present in your project
definition), lines 1 and 2.
Add the taskdef
pointing to the resource and the jar file (in this example we point to location on the file system where the jar has been extracted manually - adjust if you have used Ivy to manage the dependency). This appears in lines 4 to 8.
Add the build event listener, conditional on the cover
property being set (to avoid unnecessary output when invoked outside Diffblue Cover). This appears on line 10, and should appear as early as possible (but after the taskdef
step).
Add a task to create the projectModule
structure (we will explain what each field does below), lines 12 onwards.
moduleName
The name of the module. Appears in the output of Diffblue Cover
Mandatory[1]
version
The version of Ant in use
Optional
location
The absolute path on the file system to that module.
Mandatory[1]
classpath
The classpath containing any production classes, third party production libraries, and third party test libraries
Mandatory
productionClasses
The absolute path to the compiled production class files
Mandatory
productionSources
The absolute path to the compiled production source code
Mandatory
testClasses
The absolute path to the compiled test classes
Mandatory
testSources
The absolute path to the test source code
Mandatory
complianceLevel
The version of java used to compile the classes in the project
Optional
encoding
The file encoding used in the project
Optional
junitReportLocation
The absolute path to the JUnit test reports
Optional
buildDirectory
The absolute path to the directory containing the compiled classes and reports
Mandatory
jacocoReport
The absolute path to the JaCoCo report file
Mandatory
jacocoDestFile
The absolute path to the JaCoCo exec file
Mandatory
jacocoFormats
The list of report formats produced during JaCoCo's report task
Optional
submodules
A list of projectModule
s that describe submodules of the project
Optional
[1] Diffblue Cover is designed to iterate across the modules if they're present. If the submodules
have been specified, then only the moduleName
and location
are mandatory - representing the root module of the project.
To configure the DiffblueBuild.yaml
file for use with ant, refer to configuring Diffblue Cover to work with your project's build system. Briefly, Diffblue Cover combines the arguments specified in that file to invoke commands as if a user had typed them on the command line.