Capturing code coverage through Integration tests with Jacoco

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
  • what are you trying to achieve
  • what have you tried so far to achieve this

SonarQube version used: 7.9
Scanner used: Maven based
Plugins used: jacoco-maven-plugin 0.8.4, Maven surefire 3.0.0, Maven failsafe 3.0.0

Trying to achieve: Code coverage through Integration tests for web services

Status so far:

  1. Web service dev code is written in Node Js
  2. Automation scripts are written in Java
  3. Jacoco plugin is integrated, code coverage information populated on SonarQube as a feed from Jacoco-it.exec as part of automation scripts execution flow.

As per SonarQube documentation,
Code coverage = Unit test coverage + Integration Test Coverage

We are not expected to work on Unit tests, so
Code coverage = Integration Test Coverage

Is this code coverage information valid? From one of the forums I referred to, it seems the integration test coverage will be covering flows at module to module level, not at the code line level. Also, this may not be referring to the dev code as its written in Javascript.

As per my understanding Lcov file is the one which gives line coverage information. This will be extracted only when we go for Unit tests.

In case I am wrong here, should I be looking for an alternative plugin for code coverage? please suggest.

If I understand correctly, you are trying to get coverage for code written in JavaScript? You will need to use coverage tool for NodeJS like https://istanbul.js.org/ and the import the coverage report in SonarQube, see documentation here https://docs.sonarqube.org/latest/analysis/coverage/

Thanks @saberduck , Yes you are correct and thanks for the solution.

Could you please throw some light on below queries as well? That would really help.

We have automation scripts written in Java [RestAssured]. But the dev code is in JavaScript. Is there a solution to capture integration test code coverage in such a setup? Is this feasible?

Hi @Shalini_09, you’ll need to use a javascript code coverage tool to generate this report and this community might not be the best place to get help on such tooling and case. Once you have your report, then you can import it into SonarQube.