差分代码覆盖率 [英] differential code coverage
问题描述
我们正在为以前未经测试的代码添加单元测试,因为需要修改该代码。由于已知任何软件包中的大多数代码都是未经测试的,因此很难获得有用的覆盖率指标。
是否有任何工具可用于衡量差异代码覆盖率,即单元测试所涵盖的给定变更集中修改的代码百分比?
使用
We're adding unit tests to previously untested code, as the need arises to modify that code. It's difficult to get useful coverage metrics since the majority of code in any package is known to be untested.
Are there any tools available to measure differential code coverage, that is, the percent of code modified in a given changeset which was covered by a unit test?
Use pycobertura. It's a command-line tool to prevent code coverage regression by diffing two coverage reports. It tells you whether your new code is better or worse than the previous version, coverage-wise.
$ pycobertura diff ./master/coverage.xml ./myfeature/coverage.xml
It's language agnostic since it just relies on the Cobertura report (XML file) generated by your testing/coverage tool.
Pycobertura can also generate HTML reports which fit nicely in CI/CD tools such as Jenkins.
https://github.com/aconrad/pycobertura
这篇关于差分代码覆盖率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!