Generate merged code coverage report for JUnit and BDD tests in Sonar using Jacoco
This tutorial guides you on how to generate generate merged code coverage report for JUnit and BDD tests in Sonar using Jacoco in Jenkins pipeline. If you wanted to achieve the Code Coverage criteria (%) with both Junit and BDD tests that was set in the pipeline as gating element to generate builds for deployments.
Generate merged code coverage report for JUnit and BDD tests in Sonar using Jacoco
In our previous article we had seen how to generate code coverage report for JUnit tests using Jacoco Maven Plugin. There would be a situation where developer will not be able to cover BDD cucumber tests for all the code that is written. Hence, you may want to cover unit tests for the remaining code using Junit.
In this article let’s learn approach to solve this, on how to generate combined code coverage report for both JUnit and BDD tests.Below are the step by step procedure that you need to work on in order to generate combined code coverage report in Jenkins pipeline.
1) Write Junit tests for the code, for which BDD tests can’t be written.
2) Then in your Jenkins pipeline you need to include stage for JUnit analysis and make sure it produce “jacaco.exec” coverage file.
3) Also, make sure that BDD acceptance tests too generating “exec” coverage file. Once your application code is running locally on Jenkins pipeline with Jacoco Java Agent enabled, then BDD tests will run and Jacoco agent will start recording the coverage.
4) Next, you need to combine both “exec” coverage files using Jacoco merge command as shown below.
java -jar jacococli.jar merge [<execfiles> ...] --destfile <path> [--help] [--quiet]
For example,
java -jar jacococli.jar merge first.exec second.exec --destfile finalmerged.exec
5) After, you run the above command, it would give the combined code coverage for both JUnit and BDD tests.
6) Finally, you can convert finalmerged.exec to xml report and publish it in Sonar server.
That’s it. Now you can have combined code coverage analysis for both JUnit and BDD tests in Sonar Server.
Hope it helped 🙂
Also See:
- Set or change root password in Ubuntu Linux
- Linux: sudo: apt-get: command not found
- Install GUI on Ubuntu Server ?
- How to Start Stop Restart MariaDB on Linux OS ?
- Putty Fatal Error No supported authentication methods available
- How to find which users belongs to a specific group in linux
- Give write permissions for specific user or group for specific folder in linux
- How to unzip a zip file from Terminal (Google Cloud Shell)
- Build a Docker Image with a Dockerfile and Cloud Build in GCP?
- How to force host clock sync or update using public NTP ?
- MariaDB – How to set max_connections permanently ?
- How to create GCP project on Google Cloud Platform
- Is it possible to change Google Cloud Platform Project ID ?
- Create non-root SSH user account and provide access to specific folders
- MySQL : How to grant all privileges to the user on database ?
- How to install OpenJDK 11 in Ubuntu Machine ?
- Amazon Linux AMI : apt-get command not found
- How to get the first and last element of a list in Python ?
- Connect to Github using SSH ?
- Check OS version in Linux from command line ?
- Error: You’ll have to kill the Xvnc process manually
- How to install and configure VNC on Ubuntu 20.04 with graphical desktop?
References