Another very useful test-related metric is code coverage. Code coverage gives an indication of what parts of your application were executed during the tests. While this in itself is not a sufficient indication of quality testing (it is easy to execute an entire application without actually testing anything, and code coverage metrics provide no indication of the quality or accuracy of your tests), it is a very good indication of code that has not been tested. And, if your team is introducing rigorous testing practices such as Test-Driven-Development, code coverage can be a good indicator of how well these practices are being applied.
Code coverage analysis is a CPU and memory-intensive process, and will slow down your build job significantly. For this reason, you will typically run code coverage metrics in a separate Jenkins build job, to be run after your unit and integration tests are successful.
There are many code coverage tools available, and several are supported in Jenkins, all through dedicated plugins. Java developers can pick between Cobertura and Emma, two popular open source code coverage tools, or Clover, a powerful commercial code coverage tool from Atlassian. For .NET projects, you can use NCover.
The behavior and configuration of all of these tools is similar. In this section, we will look at Cobertura.
Cobertura is an open source code coverage tool for Java and Groovy that is easy to use and integrates well with both ...