Extracting Coverage Data programmatically

Still need help?

The Atlassian Community is here for you.

Ask the community

Using XPath with Clover's XML reports

Clover's XML reports provide detailed coverage data in a format that is easy to access programmatically using XPath. XML coverage reports can be generated by the <clover-report> or <clover-historypoint> Ant tasks. The following example XPath expressions show how to extract data from a Clover XML coverage report:

/coverage/project/metrics[@statements]

The above statement extracts the total number of statements in the project.

/coverage/project/metrics[@coveredstatements]

The above extracts the total number of covered statements in the project.

/coverage/project/package[name='com.foo.bar']/metrics[@statements]

The above extracts the total number of statements in the package com.foo.bar.

/coverage/project/package[name='com.foo.bar']/metrics[@coveredstatements]

The above extracts the total number of covered statements in the package com.foo.bar.

The following code example demonstrates simple extraction of coverage data from a Clover XML report: 

import javax.xml.xpath.*;

XPath xpath = XPathFactory.newInstance().newXPath();
String stmtExpr = "/coverage/project/metrics[@statements]";
String coveredStmtExpr = "/coverage/project/metrics[@coveredstatements]";
InputSource inputSource = new InputSource("coverage.xml");
Double projectStatements = (Double) xpath.evaluate(expression, inputSource,
                                                    XPathConstants.NUMBER);
Double projectCoveredStatements = (Double) xpath.evaluate(expression, inputSource,
                                                           XPathConstants.NUMBER);
Last modified on Jan 14, 2017

Was this helpful?

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