The <clover-instr> task produces instrumented versions of sets of source files. These can then be compiled in place of the original source to produce an instrumented build. The <clover-instr> task is provided for users who can't make use of the standard <clover-setup> integration task. The <clover-setup> task offers a simpler and less intrusive integration option for most users.
The basic nesting of elements within the <clover-instr> task is as follows:
|
<clover-instr> |
Attribute |
Description |
Required |
|---|---|---|
initstring |
The Clover initString describes the location of the Clover coverage database. Typically this is a relative or absolute file reference, e.g. |
No. |
source |
The source level to process source files at. It is recommended that you set this parameter, either here or on |
No; defaults to the Java version detected at runtime. |
destdir |
The directory into which Clover will write an instrumented copy of the source code. |
Yes. |
srcdir |
The directory of source code to instrument. |
Yes, unless a nested clover-instr element is used. |
flushpolicy |
This attribute controls how Clover flushes coverage data during a test run. Valid values are |
No; defaults to |
flushinterval |
When the flushpolicy is set to interval or threaded this value is the minimum period between flush operations (in milliseconds). |
No. |
relative |
This controls whether the |
No; defaults to " |
fullyQualifyJavaLang |
This should only be set to " |
No; defaults to " |
recordTestResults |
If set to " |
No; defaults to " |
Specifies a set of source files to instrument.
Specifies a method Context definition. See Using Coverage Contexts for more information.
Attribute |
Description |
Required |
|---|---|---|
name |
The name for this context. Must be unique, and not be one of the reserved context names (see Using Coverage Contexts). |
Yes. |
regexp |
A Perl 5 Regexp that defines the context. This regexp should match the method signatures of methods you wish to include in this context. Note that when method signatures are tested against this regexp, whitespace is normalised and comments are ignored. |
Yes. |
Specifies a statement Context definition. See Using Coverage Contexts for more information.
Attribute |
Description |
Required |
|---|---|---|
name |
The name for this context. Must be unique, and not be one of the reserved context names (see Using Coverage Contexts). |
Yes. |
regexp |
A Perl 5 Regexp that defines the context. This regexp should match statements you wish to include in this context. Note that when statements are tested against this regexp, whitespace is normalised and comments are ignored. |
Yes. |
<clover-instr srcdir="src" destdir="instr"/> |
Produce an instrumented copy of all source files in the srcdir into the destdir. The Clover registry is at the default location.
<clover-instr destdir="instr"/>
<fileset dir="src">
<include name="**/*.java"/>
</fileset>
</clover-instr>
|
This example achieves the same as the first example, but using an embedded fileset.
<clover-instr destdir="instr"/>
<testSources dir="src">
<include name="**/*Test.java"/>
<testclass name=".*Test">
<testmethod name=".*Bag.*"/> <!-- only the Bag related tests -->
</testclass>
</testSources>
</clover-instr>
|
This example produces an instrumented copy which recognises all of the following as tests: classes in the directory "src"; classes in files whose names end with "Test"; methods whose names contain with "Bag".
By default Clover will write coverage data to disk when the hosting JVM exits, via a shutdown hook. This is not always practical, particularly when the application you are testing runs in an Application Server. In this situation, you can configure Clover to use 'interval' flushing, where coverage data is written out periodically during execution:
<clover-instr flushpolicy="interval" flushinterval="5000" srcdir="src" destdir="instr" /> |
The "flushinterval" defines in milliseconds the minimum interval between coverage writes.
By default, Clover writes its internal database to the .clover directory relative to the project's basedir. To override this location, use the initstring attribute.
<clover-instr initstring="clover-db/coverage.db" srcdir="src" destdir="instr"/> |
This example will use clover-db/coverage.db as the location for the Clover database. Note that the directory clover-db should exist before running this task.