Created
November 30, 2016 23:53
-
-
Save timmolderez/721775361da0220d8203bae584208a41 to your computer and use it in GitHub Desktop.
Test code coverage in GitLab CI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
To compute test code coverage, whenever someone pushes to the git repository: | |
1 - First add the following two plugins to the <plugins> section of your pom.xml. | |
The Surefire plugin executes unit tests, and the Jacoco plugin will compute test coverage: | |
<plugin> | |
<groupId>org.jacoco</groupId> | |
<artifactId>jacoco-maven-plugin</artifactId> | |
<version>0.7.7.201606060606</version> | |
<executions> | |
<execution> | |
<id>pre-unit-test</id> | |
<goals><goal>prepare-agent</goal></goals> | |
<configuration> | |
<destFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</destFile> | |
<propertyName>surefireArgLine</propertyName> | |
</configuration> | |
</execution> | |
<execution> | |
<id>post-unit-test</id> | |
<phase>test</phase> | |
<goals><goal>report</goal></goals> | |
<configuration> | |
<dataFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</dataFile> | |
<outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory> | |
</configuration> | |
</execution> | |
</executions> | |
</plugin> | |
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-surefire-plugin</artifactId> | |
<version>2.15</version> | |
<configuration> | |
<argLine>${surefireArgLine}</argLine> | |
<skipTests>${skip.unit.tests}</skipTests> | |
</configuration> | |
</plugin> | |
2 - Next, add these two entries to the <properties> section of pom.xml. | |
This will ensure that test coverage results are also uploaded to the SonarQube server: | |
<sonar.junit.reportsPath>target/surefire-reports</sonar.junit.reportsPath> | |
<sonar.jacoco.reportPath>target/coverage-reports/jacoco-ut.exec</sonar.jacoco.reportPath> | |
3 - Done! Push your changes to the git repository, then wait for the continuous integration build to finish. | |
Once this is done, you can browse test coverage results at the SonarQube server: http://wilma.vub.ac.be:9000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment