Using Test Optimization in Maven

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.

Command-line Quick Start

The quickest possible way to start using Test Optimization in Clover-for-Maven 2 and 3 is to run the following command:

mvn clover:setup clover:optimize test clover:snapshot

By default, the snapshot file gets saved to ${basedir}/.clover/clover.snapshot. It can be deleted by running the clover:clean goal. You can also specify an alternative location using -Dmaven.clover.snaphost=/path/to/clover.snapshot. This file is needed to optimize subsequent builds, so please ensure that it won't be removed between builds (don't keep it in a /target directory, for instance).

For further documentation on these goals, see the Maven site docs:

Alternatively, add the following profile to the profiles element in your pom.xml.

Editing pom.xml for Test Optimization

To enable Clover's test optimization functionality, add the following profile to the profiles element in your pom.xml:

<profiles>
    <profile>
        <id>clover.optimize</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>com.atlassian.maven.plugins</groupId>
                    <artifactId>clover-maven-plugin</artifactId>
                    <version>4.1.1</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

Test Optimization In-Action

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 clover: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.

 

 

 

Last modified on Dec 8, 2015

Was this helpful?

Yes
No
Provide feedback about this article

Not finding the help you need?

Ask the community

Powered by Confluence and Scroll Viewport.