In this little example I present you how to easily run code coverage analysis for integration tests.
-
Compile the project with Maven first, as the class files need to be available for the Code Coverage Analysis:
mvn clean package
-
Download the Jacoco Agent from here.
-
Place it in the root of the repository (as it is linked in the docker-compose.yml)
-
Start the docker-compose stack.
docker-compose up -d
-
Connect to the maven container and change to /app:
docker exec -it jacoco_maven_1 bash bash-4.3# cd /app
-
Fetch the JaCoCo Dump:
mvn jacoco:dump -Djacoco.address=app
-
Run the SonarQube Analysis:
mvn sonar:sonar -Dsonar.host.url=http://sonar:9000
-
Access the SonarQube Analysis under http://localhost:9000 and see the coverage report. It should say 0% of your code is covered.
-
Access the sample application under http://localhost:8888/jacoco-example. Do some math calculations to see the analysis work.
-
Fetch the JaCoCo Dump again:
mvn jacoco:dump -Djacoco.address=app
-
Run the SonarQube Analysis again:
mvn sonar:sonar -Dsonar.host.url=http://sonar:9000
-
Access the SonarQube Analysis under http://localhost:9000 and see the coverage report. You should see 85.7% of Code Coverage.