Best practice for unit and integration tests coverage

Hi guys, can you share the best practice for evaluating both unit and integration code coverage during CI?
Am I right to understand I need to wait for both test cycles to complete before scanning with the two coverage results, all in one command?
Can/should we separate the reporting of these the two test cycles coverages? it’s just that the integration cycle takes longer to complete…


This is something of a perennial topic. As it stands today, you cannot update an already-reported analysis with additional data. Specifically, you cannot analyze with the unit test coverage and then amend that analysis with the integration test report.

Unfortunately, yes. You have to wait for both to complete and feed them in at the same time.


Thought so… can the two be reported together but separately from the code scan itself? so I can provide non-coverage metrics first and then later add the coverage on top of it?

Negative. All project data is updated together as part of the analysis process (scanner execution + background task).

Thought so too :frowning:

Thanks for the information!

Will I see coverages separate for unit and integration tests if I submit them to two different branches in Sonarqube?

1 Like


We never merge branch data. If you submit them with different branches, then one branch will reflect unit tests and the other will reflect integration tests.

What you won’t get out of that is what the overlap is. So if you’re going to go down this road, I suggest you do it 3 ways: one branch with ITs, one with UTs and one with both.


Thanks Ann!

Yes that definitely helped.

So now I do the following:

  • mvn clean verify (with other required params) and use the generated a jacoco-it/jacoco.xml to submit to SonarQube branch LEGO-516-IT. Using -Dsonar.coverage.jacoco.xmlReportPaths=target/site/jacoco-it/jacoco.xml command.
  • mvn clean install (with other required params) and use the generated a jacoco-ut/jacoco.xml to submit to SonarQube branch LEGO-516-UT. Using -Dsonar.coverage.jacoco.xmlReportPaths=target/site/jacoco-ut/jacoco.xml
    and finally
  • mvn sonar: sonar and submit both jacoco-it/jacoco.xml and jacoco-ut/jacoco.xml (comma separated) to the Sonarqube branch LEGO-516. Using -Dsonar.coverage.jacoco.xmlReportPaths=target/site/jacoco-ut/jacoco.xml,target/site/jacoco-it/jacoco.xml

I see 3 separate coverage values for these 3 branches I created. However, I see test counts only for unit tests and not for integration tests. Is there a way to get that?

1 Like

Also, how would the quality gates behave for these 3 branches? Can I set different a gate for each branch?


In your IT-only branch, submit the IT counts as UT counts.

Nope. The main project’s QG will be applied for all.


Hi Ann,

Im not sure how to submit IT counts as UT counts.


How do you submit UT counts?


I dont have a step specifically for doing that. The jacoco maven plugin integrated with maven-surefire does that for me.

Sorry, I’m not sure what to tell you at this point.

Can you share how you resolved this issue. Thanks

I am also trouble to show c# solution Integration test counts . can any one please help on this.

Here Is my commandlIne steps.

  1. dotnet restore “My Solution Name Here”
  2. dotnet sonarscanner begin /k:“solution Name” /“hostUrl” /d:sonar.login=“token”
  3. dotnet build “SolutionName” -c Release -o /app/build
  4. dotnet test “SourcesPath” /p:CollectCoverage=true /p:CoverletOutputFormat=opencover
  5. dotnet sonarscanner end /d:sonar.login=token