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.
This page contains the basic steps for adding Clover's Test Optimization to an existing Maven configuration.
WARNING: Clover's build optimization in Maven runs in the default build lifecycle - not the forked Clover lifecycle. Please pay attention not to deploy clovered artifacts to your repository. Test Optimization is only recommended for saving time during development - not production deployment.
The quickest possible way to start using Test Optimization in Clover-for-Maven 2 and 3 is to run the following command:
mvn com.atlassian.maven.plugins:maven-clover2-plugin:setup com.atlassian.maven.plugins:maven-clover2-plugin:optimize test com.atlassian.maven.plugins:maven-clover2-plugin:snapshot
By default, the snapshot file gets saved to ${basedir}/.clover/clover.snapshot
. This file is needed to optimize subsequent builds. It can be deleted by running the clover2:clean goal. You can also specify an alternative location using -Dmaven.clover.snaphost=/path/to/clover.snapshot .
For further documentation on these goals, see the maven site docs:
Alternatively, add the following profile to the profiles element in your pom.xml.
To enable Clover's test optimization functionality, add the following profile to the profiles element in your pom.xml:
<profiles> <profile> <id>clover</id> <build> <plugins> <plugin> <groupId>com.atlassian.maven.plugins</groupId> <artifactId>maven-clover2-plugin</artifactId> <version>2.5.0</version> <executions> <execution> <goals> <goal>setup</goal> <goal>optimize</goal> <goal>snapshot</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </profile> </profiles>
This will then make it possible to run the following command:
mvn integration-test -Pclover.optimize
The first time Clover Test Optimization is used a full test run will be done. You should see the following log message appear in the maven stdout:
If you then rerun the build, without modifying any source files (and ensuring the snapshot file is not deleted) you should see the following:
If a source file is modified in any way (including whitespace changes), and you re-run the build, only TestCases that cover the modified file will be run, for instance:
By default, the same snapshot file is updated for 10 consecutive builds. On the 10th build, the snapshot file is deleted and recreated. You can adjust this setting via the fullRunEvery option on the clover2:optimize goal.
TIP: If your terminal supports ANSI escape sequences (OS X, Linux by default), supply the -Dansi.color=true
property on the command line to have your build optimization in full color.