Jacoco code coverage report intellij
What you will learn here about Jacoco in Java
- Jacoco code coverage report intellij
Here we will see how to integrate Jacoco in java and how to generate code coverage report using Jacoco in intellij.
Jacoco code coverage report intellij
Please follow the following steps to know how to generate jacoco code coverage report in intellij.
1)First create simple maven project
2)Then add junit dependency in your pom.xml which is shown below
<dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.8.2</version> </dependency> </dependencies>
3)Add Jacoco Plugin dependency in pom.xml which is shown below
<build> <plugins> <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.8.7</version> <executions> <execution> <id>prepare-agent</id> <goals> <goal>prepare-agent</goal> </goals> </execution> <execution> <id>report</id> <phase>prepare-package</phase> <goals> <goal>report</goal> </goals> </execution> <execution> <id>post-unit-test</id> <phase>test</phase> <goals> <goal>report</goal> </goals> <configuration> <!-- Sets the path to the file which contains the execution data. --> <dataFile>target/jacoco.exec</dataFile> <!-- Sets the output directory for the code coverage report. --> <outputDirectory>target/my-reports</outputDirectory> </configuration> </execution> </executions> </plugin> </plugins> </build>
4)Create simple class which you want to cover. Below we have created HelloWorld class.
5)Now write Test case for that class which is shown below
6)Now follow following steps
Click on maven -> click on Project Name -> click on Life Cycle -> click on clean
Click on maven -> click on Project Name -> click on Life Cycle -> click on compile
Click on maven -> click on Project Name -> click on Life Cycle -> click on test
7)Wait for successful result which is shown below
8)After successful result. Go to following path and click on index.html
Project path -> project name -> target folder -> my-reports -> click on index.html
9)You will see following kind of result in browser.