faranak-cs / spring-rest-app

REST app in Spring
0 stars 0 forks source link

Code Coverage (Heatmap) #19

Closed faranak-cs closed 3 months ago

faranak-cs commented 3 months ago

Use JaCoCo Maven plugin for code coverage.

"If the code coverage is below 80 percent, the maven build should fail"

faranak-cs commented 3 months ago

Blog: https://www.baeldung.com/jacoco

faranak-cs commented 3 months ago

Add the following plugin in pom.xml

<plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>${jacoco.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>report</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
faranak-cs commented 3 months ago

Use the following command to build the byte-code generated by JaCoCo into readable format:

mvn jacoco:report
faranak-cs commented 3 months ago

Go to target/site/jacoco and open index.html in browser