覆盖计数
行覆盖率:度量被测程序的每行代码是否被执行,判断标准行中是否至少有一个指令被执行。
类覆盖率:度量计算class类文件是否被执行。
分支覆盖率:度量if和switch语句的分支覆盖情况,计算一个方法里面的。
总分支数,确定执行和不执行的 分支数量。
方法覆盖率:度量被测程序的方法执行情况,是否执行取决于方法中是否有至少一个指令被执行。
指令覆盖:计数单元是单个java二进制代码指令,指令覆盖率提供了代码是否被执行的信息,度量完全 独立源码格式。
圈复杂度:在(线性)组合中,计算在一个方法里面所有可能路径的最小数目,缺失的复杂度同样表示测 试案例没有完全覆盖到这个模块。
jacoco-maven-plugin
goal | phrase | |
---|---|---|
help | ||
prepare-agent | initialize | Resulting coverage information is collected during execution and by default written to a file when the process terminates.【生成 jacoco.exec】 |
prepare-agent-integration | pre-integration-test | 【生成 jacoco-it.exec】 |
merge | generate-resources | merging a set of execution data files (*.exec ) into a single file |
report | verify | Creates a code coverage report for tests of a single project in multiple formats (HTML, XML, and CSV).【从jacoco.exec生成报告(site/jacoo),因而依赖prepare-agent 】 |
report-integration | verify | 【从jacoco-it.exec生成报告(site/jacoo),因而依赖prepare-agent-integration 】 |
report-aggregate | ||
check | verify | Checks that the code coverage metrics are being met. |
dump | post-integration-test | Request a dump over TCP/IP from a JaCoCo agent running in tcpserver mode. |
instrument | process-classes | Performs offline instrumentation. Note that after execution of test you must restore original classes with help of “restore-instrumented-classes” goal. |
restore-instrumented-classes | prepare-package | Restores original classes as they were before offline instrumentation. |
直接运行
1 |
|
配置运行
1 |
|
mvn clean install
report
样例: