1. What is Cobertura ?
Cobertura is a free Java tool that calculates the percentage of code accessed by tests. It can be used to identify which parts of your Java program are lacking test coverage. It is based on jcoverage.
2. Cobertura Advantages and Features
- Cobertura is a open source Java tool
- Helps to get the code coverage details
- It shows the percentage of line and branch test cases have been covered
- Cobertura report shows which line of code is lacking of test cases
- It can be executed with Maven, Ant or command line
3. What is Line and Branch Coverage?
Line coverage –> During the test cases run how much percentage of lines have been covered
Branch coverage-> During the test coverage how much percentage of branches have been covered.
4. Cobertura Example
Below example will show how cobertura calculating line and branch coverage.
1. Create a Maven Project and add below plugin/configuration in pom.xml
2. Create a Sample Java Program and its Junit Test
3. Junit test class
Run it (Use below command)
mvn clean install cobertura:cobertura