Integration tests count ignored in coverage measures - maven

I'm running a Maven multi-module project, and using Sonar Runner to analyze the project for SonarQube 6.3. This project contains both unit and integration tests in every modules. I succeeded generating reports for UT and IT in target/jacoco-ut.exec and target/jacoco-it.exec.
I think analysis parameters for Sonar Runner are good, as I can see both reports are processed and merged during analysis.
From SonarQube 6.3, there's no difference anymore between unit tests and integration tests, though the only measure reported is "Unit tests", which suggests integration tests are ignored.
When I look at the coverage measures in SonarQube, I'm surprised because the number of tests reported is not the sum of the number of unit tests and the number of integration tests. Integration tests are not listed in the measures. To me, if both unit tests and integration tests were merged in SonarQube, I understand there shall both appear in measures, but that's not the case.
I can't find anything in SonarQube documentation about integration tests inclusion in measures. There are only notes that they are merged during analysis, though I don't see anything about my integration tests in the coverage measures.
How can I see integration tests and unit tests in coverage measures?

All tests are now merged into "Coverage", so those numbers include the sum of UT and IT coverage. However prior to the merger there were no metrics about integrations tests themselves (test count, duration, errors, &etc) so there was nothing there to merge.
In fact, metrics about tests (count, errors...) really aren't seen as relevant in general and remain in the system only because they've been grandfathered.

Related

jenkins jacoco plugin unit and integration coverage separately

I am integrating jenkins jacoco plugin in the jenkins pipeline at two different stages, one after the unit tests which produced a jacoco.exec file.
I used the jacoco(params) to attach this with the build.
Right after that, I run my integration tests with coverage, and produced jaccoco-it.exec and used jacoco(params) to attach it to the build.
But my build shows two different coverage charts with the merged coverage reports.
I would like to get the unit test coverage and integration test coverage separately on the build. Is this possible at all? I could not find any documentation related to this use case.

How to force code coverage to Zero?

I have several java projects with no unit test cases. When I try to analyse these projects using SonarQube I am unable to get unit test code coverage because it doesn't have any test cases. As per my research I saw that I can force it to show it as zero if there are no unit test cases. The official Jacoco Java documentation mentions sonar.jacoco.reportMissing.force.zero=true.
My SonarQube analysis will be done using maven builds and SonarQube 5.6.6 and sonar-java 4.11.0.10660.
How can I set this parameter in maven so that it can show as zero unit test cases in my coverage?
From version 6.2 SonarQube does this automatically where the behavior is supported by the analyzers. Before that version, availability of the feature is spotty and not entirely reliable. For best results you should upgrade SonarQube.
That said, you can set that property on the analysis command line like so:
mvn sonar:sonar -Dsonar.jacoco.reportMissing.force.zero=true
Or by setting a property in your pom, as shown in the docs
Update 16 Dec 2019
Most language analyzers now calculate Executable Lines, so files omitted from the coverage report are included in calculations anyway. But that only kicks in if you provide coverage reports. No coverage reports -> no coverage metrics at all.

How to show Integration Test Statistics?

Im using SonarQube v6.4. I'm aware that all types of tests (Unit Tests, Integration Tests etc) have been merged together as overall coverage.
However, on the interface I can see statistics for only Unit tests, Is there a way to get the statistics for other types of tests?
Example of statistics available only for unit test
Unit Test Errors
Unit Test Failures
Skipped Unit Tests
Unit Test Success (%)
Unit Test Duration
SonarQube no longer distinguishes between different types of tests. Integration tests, Smoke Tests, Medium Tests, Regression Tests, etc. - all are now called "Unit Tests". This new naming is indeed misleading...
For to see the values navigate to your project, click on the "Measures" tab ("All" page) and scroll down to "Coverage". There you will find the current tests measure values.
Starting from version 6.6 of SonarQube you will be able to show graphs for any metric (see SonarQube's own SonarQube instance with 6.6-SNAPSHOT installed).
Navigate to any SonarQube project, click on the tab "Activity", select "Custom" from the drop down and click on "Add metric". There you can choose "Unit Test Errors", "Skipped Unit Tests", etc.
I discovered that this feature is not supported in Sonarqube. A ticket opened for this issue has already been closed as "Won't Fix" by the Sonarqube Team.
For a workaround you can check this

SonarQube incremental analysis for C#.Net UnitTest

I am using SonarQube 4.3 version to show Unit tests and other code metrics analysis results. Now I am looking for incremental preview or mode for my analysis results as described here.
I am looking to see whether the last code checked-in has a 100% unit test coverage, no security violations and has other quality gates passed.
Currently sonar gives overall combined report for all the files within project. Can we have one for the changed files in the last build as well?

Can Sonar calculate overall test coverage when using Cobertura?

When using Cobertura I am able to display unit and integration test coverage separately in Sonar however I can't find a way to display the overall test coverage..
The Sonar documentation implies this is possible using Jacoco but I wondered if it was also possible using Cobertura?
Many thanks
It is not possible, at least not with sonarqube 4.3.
You could however, combine unit-test-coverage generated with cobertura with integration-test-coverage generated with jacoco.
The documentation sais clearly:
"If coverage by unit tests is not computed with JaCoCo, overall coverage = integration test coverage."
You can find the documentation here:
http://docs.codehaus.org/display/SONAR/Code+Coverage+by+Integration+Tests+for+Java+Project
Sorry and good luck with yout further configuration!

Resources