Closed7
テストカバレッジレポートの種類
nodejsにおけるカバレッジツール istanbul で使われてるカバレッジレポート。jestのカバレッジオプションもistanbul内包してる。
jest --coverage
でデフォルトで生成されるレポートは
- clover.xml
- lcov-report
- lcov.info
- coverage-final.json
の4つ。
lcov-reportはlcovのHTML形式の見た目を提供している。lcov.infoはテキストベースのlcov。どちらも中身に違いはない。
clover
clover.xml という名前で出力。
Attlasian Clover という商用のカバレッジツールがあり、それの後継としてオープンソースなOpenCloverが作られた。このレポーターはおそらくOpenClover形式。
<?xml version="1.0" encoding="UTF-8"?>
<coverage generated="1500242170615" clover="3.2.0">
<project timestamp="1500242170615" name="All files">
<metrics statements="161" coveredstatements="161" conditionals="24" coveredconditionals="18" methods="49" coveredmethods="49" elements="234" coveredelements="228" complexity="0" loc="161" ncloc="161" packages="9" files="15" classes="15">
<package name="src">
<metrics statements="11" coveredstatements="11" conditionals="0" coveredconditionals="0" methods="4" coveredmethods="4"/>
<file name="errors.ts" path="$PROJECT_PATH/src/errors.ts">
<metrics statements="2" coveredstatements="2" conditionals="0" coveredconditionals="0" methods="0" coveredmethods="0"/>
<line num="1" count="1" type="stmt"/>
<line num="4" count="1" type="stmt"/>
</file>
<file name="test.ts" path="$PROJECT_PATH/src/test.ts">
<metrics statements="9" coveredstatements="9" conditionals="0" coveredconditionals="0" methods="4" coveredmethods="4"/>
<line num="1" count="1" type="stmt"/>
<line num="3" count="1" type="stmt"/>
<line num="4" count="1" type="stmt"/>
<line num="6" count="1" type="stmt"/>
<line num="7" count="1" type="stmt"/>
<line num="9" count="1" type="stmt"/>
<line num="10" count="1" type="stmt"/>
<line num="12" count="1" type="stmt"/>
<line num="13" count="1" type="stmt"/>
</file>
</package>
</metrics>
</project>
</coverage>
covertura
cobertura-coverage.xml という名前で出力。
Java用のオープンソースなカバレッジツールcovertura形式。
<?xml version="1.0" ?>
<!DOCTYPE coverage SYSTEM "http://cobertura.sourceforge.net/xml/coverage-04.dtd">
<coverage lines-valid="161" lines-covered="161" line-rate="1" branches-valid="24" branches-covered="18" branch-rate="0.75" timestamp="1500242087605" complexity="0" version="0.1">
<sources>
<source>$PROJECT_PATH</source>
</sources>
<packages>
<package name="src" line-rate="1" branch-rate="1">
<classes>
<class name="errors.ts" filename="src/errors.ts" line-rate="1" branch-rate="1">
<methods>
</methods>
<lines>
<line number="1" hits="1" branch="false"/>
<line number="4" hits="1" branch="false"/>
</lines>
</class>
<class name="test.ts" filename="src/test.ts" line-rate="1" branch-rate="1">
<methods>
<method name="(anonymous_0)" hits="1" signature="()V">
<lines>
<line number="3" hits="1"/>
</lines>
</method>
<method name="(anonymous_1)" hits="1" signature="()V">
<lines>
<line number="6" hits="1"/>
</lines>
</method>
<method name="(anonymous_2)" hits="1" signature="()V">
<lines>
<line number="9" hits="1"/>
</lines>
</method>
<method name="(anonymous_3)" hits="1" signature="()V">
<lines>
<line number="12" hits="1"/>
</lines>
</method>
</methods>
<lines>
<line number="1" hits="1" branch="false"/>
<line number="3" hits="1" branch="false"/>
<line number="4" hits="1" branch="false"/>
<line number="6" hits="1" branch="false"/>
<line number="7" hits="1" branch="false"/>
<line number="9" hits="1" branch="false"/>
<line number="10" hits="1" branch="false"/>
<line number="12" hits="1" branch="false"/>
<line number="13" hits="1" branch="false"/>
</lines>
</class>
</classes>
</package>
</packages>
</coverage>
json-summary
coverage-summary.json という名前で出力。各ファイルのサマリーを表示してくれる。
{"total": {"lines":{"total":161,"covered":161,"skipped":0,"pct":100},"statements":{"total":166,"covered":166,"skipped":0,"pct":100},"functions":{"total":49,"covered":49,"skipped":0,"pct":100},"branches":{"total":24,"covered":18,"skipped":0,"pct":75}}
,"$PROJECT_PATH/src/errors.ts": {"lines":{"total":2,"covered":2,"skipped":0,"pct":100},"functions":{"total":0,"covered":0,"skipped":0,"pct":100},"statements":{"total":2,"covered":2,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}}
,"$PROJECT_PATH/src/test.ts": {"lines":{"total":9,"covered":9,"skipped":0,"pct":100},"functions":{"total":4,"covered":4,"skipped":0,"pct":100},"statements":{"total":9,"covered":9,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}}
,"$PROJECT_PATH/src/config/index.ts": {"lines":{"total":10,"covered":10,"skipped":0,"pct":100},"functions":{"total":0,"covered":0,"skipped":0,"pct":100},"statements":{"total":10,"covered":10,"skipped":0,"pct":100},"branches":{"total":8,"covered":4,"skipped":0,"pct":50}}
,"$PROJECT_PATH/src/crud/index.test.ts": {"lines":{"total":1,"covered":1,"skipped":0,"pct":100},"functions":{"total":0,"covered":0,"skipped":0,"pct":100},"statements":{"total":1,"covered":1,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}}
,"$PROJECT_PATH/src/crud/insert/index.test.ts": {"lines":{"total":36,"covered":36,"skipped":0,"pct":100},"functions":{"total":16,"covered":16,"skipped":0,"pct":100},"statements":{"total":37,"covered":37,"skipped":0,"pct":100},"branches":{"total":2,"covered":1,"skipped":0,"pct":50}}
,"$PROJECT_PATH/src/crud/insert/index.ts": {"lines":{"total":5,"covered":5,"skipped":0,"pct":100},"functions":{"total":2,"covered":2,"skipped":0,"pct":100},"statements":{"total":6,"covered":6,"skipped":0,"pct":100},"branches":{"total":6,"covered":6,"skipped":0,"pct":100}}
,"$PROJECT_PATH/src/customers/index.test.ts": {"lines":{"total":14,"covered":14,"skipped":0,"pct":100},"functions":{"total":4,"covered":4,"skipped":0,"pct":100},"statements":{"total":14,"covered":14,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}}
,"$PROJECT_PATH/src/customers/index.ts": {"lines":{"total":5,"covered":5,"skipped":0,"pct":100},"functions":{"total":1,"covered":1,"skipped":0,"pct":100},"statements":{"total":6,"covered":6,"skipped":0,"pct":100},"branches":{"total":2,"covered":2,"skipped":0,"pct":100}}
,"$PROJECT_PATH/src/init/env.ts": {"lines":{"total":2,"covered":2,"skipped":0,"pct":100},"functions":{"total":0,"covered":0,"skipped":0,"pct":100},"statements":{"total":2,"covered":2,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}}
,"$PROJECT_PATH/src/init/index.test.ts": {"lines":{"total":4,"covered":4,"skipped":0,"pct":100},"functions":{"total":2,"covered":2,"skipped":0,"pct":100},"statements":{"total":4,"covered":4,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}}
,"$PROJECT_PATH/src/init/execute/index.test.ts": {"lines":{"total":26,"covered":26,"skipped":0,"pct":100},"functions":{"total":7,"covered":7,"skipped":0,"pct":100},"statements":{"total":26,"covered":26,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}}
,"$PROJECT_PATH/src/init/execute/index.ts": {"lines":{"total":8,"covered":8,"skipped":0,"pct":100},"functions":{"total":1,"covered":1,"skipped":0,"pct":100},"statements":{"total":9,"covered":9,"skipped":0,"pct":100},"branches":{"total":2,"covered":2,"skipped":0,"pct":100}}
,"$PROJECT_PATH/src/init/gateway/index.ts": {"lines":{"total":2,"covered":2,"skipped":0,"pct":100},"functions":{"total":0,"covered":0,"skipped":0,"pct":100},"statements":{"total":2,"covered":2,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}}
,"$PROJECT_PATH/src/payments/index.test.ts": {"lines":{"total":27,"covered":27,"skipped":0,"pct":100},"functions":{"total":11,"covered":11,"skipped":0,"pct":100},"statements":{"total":28,"covered":28,"skipped":0,"pct":100},"branches":{"total":2,"covered":1,"skipped":0,"pct":50}}
,"$PROJECT_PATH/src/payments/index.ts": {"lines":{"total":10,"covered":10,"skipped":0,"pct":100},"functions":{"total":1,"covered":1,"skipped":0,"pct":100},"statements":{"total":10,"covered":10,"skipped":0,"pct":100},"branches":{"total":2,"covered":2,"skipped":0,"pct":100}}
}
json
多分istanbulが内部で扱ってるカバレッジの形だと予想。多分これを書くレポートの形に整形してるんじゃないかと仮説もってる。
{"$PROJECT_PATH/src/errors.ts": {"path":"$PROJECT_PATH/src/errors.ts","statementMap":{"0":{"start":{"line":1,"column":32},"end":{"line":1,"column":72}},"1":{"start":{"line":4,"column":2},"end":{"line":4,"column":25}}},"fnMap":{},"branchMap":{},"s":{"0":1,"1":1},"f":{},"b":{}}
,"$PROJECT_PATH/src/init/env.ts": {"path":"$PROJECT_PATH/src/init/env.ts","statementMap":{"0":{"start":{"line":1,"column":0},"end":{"line":1,"column":32}},"1":{"start":{"line":2,"column":0},"end":{"line":2,"column":16}}},"fnMap":{},"branchMap":{},"s":{"0":1,"1":1},"f":{},"b":{}}
}
lcov
LCOVはGCOVの派生でLinuxカーネルのカバレッジ測定ように作られた。GCOVはGNUツールで、特定テストで実際に実行された部分の情報を提供する。
Description
-----------
LCOV is an extension of GCOV, a GNU tool which provides information about
what parts of a program are actually executed (i.e. "covered") while running
a particular test case. The extension consists of a set of Perl scripts
which build on the textual GCOV output to implement the following enhanced
functionality:
* HTML based output: coverage rates are additionally indicated using bar
graphs and specific colors.
* Support for large projects: overview pages allow quick browsing of
coverage data by providing three levels of detail: directory view,
file view and source code view.
LCOV was initially designed to support Linux kernel coverage measurements,
but works as well for coverage measurements on standard user space
applications.
TN:
SF:$PROJECT_PATH/src/bar/index.ts
FN:7,baz
FNF:1
FNH:1
FNDA:2,baz
DA:1,1
DA:2,1
DA:3,1
DA:5,1
DA:8,2
DA:9,1
DA:13,1
DA:16,1
DA:20,1
DA:21,1
LF:10
LH:10
BRDA:8,0,0,1
BRDA:8,0,1,1
BRF:2
BRH:2
end_of_record
teamcity
IDEで有名なjetbrain社のCIサービス。
##teamcity[blockOpened name='Code Coverage Summary']
##teamcity[buildStatisticValue key='CodeCoverageAbsBCovered' value='166']
##teamcity[buildStatisticValue key='CodeCoverageAbsBTotal' value='166']
##teamcity[buildStatisticValue key='CodeCoverageAbsRCovered' value='18']
##teamcity[buildStatisticValue key='CodeCoverageAbsRTotal' value='24']
##teamcity[buildStatisticValue key='CodeCoverageAbsMCovered' value='49']
##teamcity[buildStatisticValue key='CodeCoverageAbsMTotal' value='49']
##teamcity[buildStatisticValue key='CodeCoverageAbsLCovered' value='161']
##teamcity[buildStatisticValue key='CodeCoverageAbsLTotal' value='161']
##teamcity[blockClosed name='Code Coverage Summary']
このスクラップは2022/04/19にクローズされました