开发者

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.

differential code coverage

https://github.com/aconrad/pycobertura


Continuous integration tools like Jenkins let you keep a history of test coverage and show you a graph that includes a coverage trend compared to previous builds. Example: Cobertura Jenkins Plugin


There is a gradle plugin that computes diff code coverage

https://github.com/form-com/diff-coverage-gradle

All you need is to provide diff file to the plugin or you can use git diff tool that is shown in the example


Take a look into Sonar, really good tool to analyze entire application quality and coverage.


I recently did exactly that, using JaCoCo and the ConQAT framework for code analysis. The approach is as follows:

  1. Load the source code from the baseline version and the head version (and potentially intermediary ones, if you also have done tests in-between)
  2. Compare the program history method by method to determine where changes happened
  3. Annotate coverage information to each tested revision
  4. Search for methods that have not been covered since they last changed

There is also a blog post containing a more detailed description including visualizations and more advanced topics like refactoring detection to only identify changes worth testing.


You can use diff-test-coverage for this. diff-test-coverage is a Node.js commandline tool which filters test coverage based on a (source control) diff.

It works by filtering the coverage report information, so it can report the coverage information for new code.

differential code coverage

It supports both Git and Mercurial and all common coverage report formats.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜