Extracting Coverage Data programmatically

このページの内容

お困りですか?

アトラシアン コミュニティをご利用ください。

コミュニティに質問

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);
最終更新日: 2017 年 1 月 14 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.