This page contains the basic steps for adding Clover's Test Optimization to an existing Ant configuration.
Follow the steps in this document to set up Clover's Test Optimization, which allows targeted testing of only the code which has changed since the last build.
These steps assume your build is Clover-enabled already (in particular it has a
with.clover task already set up and has a taskdef established for the Clover Ant tasks). You will have to complement this quick start guide with basic Clover configuration information.
These steps also assume that your build file is currently used for a CI (Continuous Integration) build and possibly for general builds (e.g. On a developer's own machine). Below, we describe how you can take that build file and add sections to bake in Test Optimization. Adding optional support for Test Optimization (switching it on/off), specifying whether test minimisation is performed and test reordering other than the default 'failfast' are advanced options which are covered elsewhere.
BEFORE YOU START
Try to ensure your unit tests do not have dependencies between them as this may cause optimized builds to fail more frequently than usual.
- You will need to use this:
If you are using Ant 1.7 or later, you will also need to use the following:
- Choose a location for the test snapshot file that can survive clean builds. This location:
<clover-clean/>as, by default, it won't delete snapshots. Add a property for this, as in the following example:
The default is not as good as manually deleting this directory each build, but it is workable if you only use
- Add a target to generate the test snapshot:
- For Ant 1.7 and later, modify the
batchtestelement of the
<junit/>task used to test your application, so that the filesets are wrapped in the
clover-optimized-testsetelement. See the following example: This becomes the following:
- For Ant 1.6, modify any fileset in the batchtest element and add a clover-optimized-selector element:
This becomes the following:
Optimized test reordering is only available for Ant 1.7 and using the
clover-optimized-testsetelement. Ant 1.6 and
clover-optimized-selectoronly permit the minimisation of the tests run, not optimal ordering.
- Run the optimized build (this will typically be run by their CI plan). Assuming a "run.tests" target modified in steps 4/5 (with appropriate dependencies so that the code is instrumented/compiled/packaged):