clover-check

Still need help?

The Atlassian Community is here for you.

Ask the community

Description

The <clover-check> task tests project/package code coverage against criteria, optionally failing the build if the criteria are not met. This task needs to be run after coverage has been recorded.

Parameters

ocumentationAttribute

Description

Required

codeType

Since 3.1.6: Specifies which sources shall be taken for calculation.

Valid values are: APPLICATION (business code), TEST (test code), ALL (business + test code).

No; Default value: APPLICATION.

conditionalTarget

The target percentage conditional coverage for the project.

At least one of target, methodTarget, statementTarget or conditionalTarget is required, unless nested clover-check elements are specified.

failureProperty

Specifies the name of a property to be set if the target is not met. If the target is not met, the property will contain a text description of the failure(s).

No.

filter

comma or space separated list of contexts to exclude when calculating coverage. See Using Coverage Contexts.

No.

haltOnFailure

Specifies if the build should be halted if the target is not met.

No; default is "false".

historydir

Allows you to specify a location for historical build data, along with a configurable threshold expressed as a percentage – used to cause the build to fail if coverage has dropped. This attribute is passed down to specified packages, then the same test is done for these at the package level.

No. Example:
historyDir="/history" threshold="1%"

includeFailedTestCoverage

Specifies whether to include failed test coverage when calculating the total coverage percentage.

No; defaults to "false".

initstring

The initstring of the coverage database.

No; If not specified here, Clover will look in the default location (${basedir}/.clover). If you have specified an initstring on the <clover-setup> task, you must ensure that <clover-setup> is called prior to the execution of this task.

methodTarget

The target percentage method coverage for the project.

At least one of target, methodTarget, statementTarget or conditionalTarget is required, unless nested clover-check elements are specified.

span

Specifies how far back in time to include coverage recordings from since the last Clover build. See Using Spans.

No; default includes "all coverage data found".

statementTarget

The target percentage statement coverage for the project.

At least one of target, methodTarget, statementTarget or conditionalTarget is required, unless nested clover-check elements are specified.

target

The target percentage total coverage for the project. e.g. "10%"

At least one of target, methodTarget, statementTarget or conditionalTarget is required, unless nested clover-check elements are specified.

Important note on target, methodTarget, statementTarget, conditionalTarget

Comparison of actual value with a target percentage is performed with such numerical precision as number of fractional digits set for a target percentage. A standard rounding is used (BigDecimal.ROUND_HALF_EVEN).

For example, if actual coverage value is 99.9% then for the target="100%" a build will pass, whereas for the target="100.000000%" a build will fail.

 

Nested elements of <clover-check>

<package>

Specifies a target for a named package.

Parameters

Attribute

Description

Required

conditionalTarget

The target percentage conditional coverage for the package.

At least one of target, methodTarget, statementTarget or conditionalTarget is required.

methodTarget

The target percentage method coverage for the package.

At least one of target, methodTarget, statementTarget or conditionalTarget is required.

name

The name of the package.

Either (but not both) of name or regex is required.

regex

Regular expression to match package names.

Either (but not both) of name or regex is required.

statementTarget

The target percentage statement coverage for the package.

At least one of target, methodTarget, statementTarget or conditionalTarget is required.

target

The target percentage total coverage for the package. e.g. "10%"

At least one of target, methodTarget, statementTarget or conditionalTarget is required.

<testsources>

<testsources> is an Ant fileset that can be used to distinguish test source code from application source code. All files included in the fileset will be displayed in the separate 'Test' node of the coverage tree. If omitted, Clover's default test detection algorithm will be used to distinguish test sources.

<testResults>

An optional Ant fileset containing a list of test result XML files.

<testresults> is generally not required by most users, as the built-in test results will provide all required information in the majority of cases. For more details please see 'Advanced Usage'.

Examples

<clover-check target="80%"/>

Tests if total percentage coverage is at least 80%. If not, a message is logged and the build continues.

<clover-check target="80%"
              haltOnFailure="true"/>

Tests if total percentage coverage is at least 80%. If not, a message is logged and the build fails.

<clover-check target="80%"
              failureProperty="coverageFailed"/>

Tests if total percentage coverage is at least 80%. If not, a message is logged and the project property coverageFailed is set.

<clover-check target="80%"
   <package name="com.acme.killerapp.core" target="70%"/>
   <package name="com.acme.killerapp.ai" target="40%"/>
</clover-check>

Tests if:

  • total percentage coverage for project is at least 80%.
  • total percentage coverage for package com.acme.killerapp.core is at least 70%.
  • total percentage coverage for package com.acme.killerapp.ai is at least 40%.

If any of these criteria are not met, a message is logged and the build continues.

<clover-check target="80%"
             filter="catch">
   <package name="com.acme.killerapp.core" target="70%"/>
   <package name="com.acme.killerapp.ai" target="40%"/>
</clover-check>

As above, but doesn't include coverage of catch blocks when measuring criteria.

<clover-check target="80%" conditionalTarget="90%"
             filter="catch">
   <package name="com.acme.killerapp.core" target="70%"/>
   <package name="com.acme.killerapp.ai" target="40%"/>
</clover-check>

As previous example, but also ensures that the project conditional coverage is at least 90%.

<clover-check>
   <package regex="com.acme.killerapp.core.*" target="70%"/>
</clover-check>

Tests if coverage for com.acme.killerapp.core and all subpackages is at least 70%.

Last modified on Mar 1, 2017

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.