QA Automation : API Code Coverage with JaCoCo and Sonarqube .

Note — Written this article assuming that you have an independent API automation framework which are pointing to micro-services/product application.

The code coverage plays a very important role while doing QA and product automation , isn't it? Lets see — why it is important to rely on code coverage report.

SDET and QA functional tester both are claiming that they have covered all functional features automation and it’s test cases. (let’s say they have claimed 90%) . They have decided to execute the code coverage to prove their claim and interestingly the coverage report was showing only 55%. Now, This will surely help them to find out missing test cases by analysis the report which can further help them to increase the coverage.

You will find many tools to generate code coverage report where few of them are paid and few of are open source tools. We will discuss here more about JaCoCo and how we can configure it.

JaCoCo : It is an open source code coverage analysis tool in java vm based environment . You can use either ant task or jacoco maven plugin.

SonarQube : it is an automatic code review tool to detect bugs, vulnerabilities, and code smells in your code. It can integrate with your existing workflow to enable continuous code inspection across your project branches and pull requests.

Pre-requisite :

  1. Jacoco and Sonarqube jars.
  2. Jenkins File
  3. Docker file
  4. Create Sonarqube server — will discuss the steps .
  5. Note —You should have Docker installed on your machine , Jenkins server for CI/CD and repo’s on github.

There must be two repo’s needs to be pull on your slave/vm/local machine

  • Application Under Test
  • Automation Repo
  1. Jenkins and Sonarqube jars —

Download the below jars from the Jacoco platform and make sure it should get checked in your project. All these below jars should be reside under coverage folder/any folder.

2. Jenkins :

Let’s create a Jenkins File (jenkinsfile — copy and paste below content and replace the job name accordingly). and check in to your project.

3. Docker File — Get the below content and create a Dcoker file and check in to your project.

4. Sonarqube Container —

  • Fire the below command to run Sonarqube on Docker
  • docker run -d — name sonarqube -e SONAR_ES_BOOTSTRAP_CHECKS_DISABLE=true -p 9001:9000 sonarqube:latest
  • Navigate to below link
  • http://localhost:9000/
  • setup your userName and Password
  • Create Project — provide the project and click on setup
  • Generate Token — Enter the token name which will generate the token which you can use it in your pom.xml file (if you are going to use jacoco maven plugin then you can use generated token — this is out of scope for this article)

Your SonarQube setup is up and running successfully.

5. Final step to create Jenkins Jobs which is quite straightforward-

  • Create two Freestyle Jenkins job — 1. AUT and 2. Automation project
  • Application Under Test :

Source Code Management :

Build : Enter the Maven Command

clean install -DskipTests

  • Automation Project :