I am using Sonar Qube Version 5.6 with jacoco 0.7.9 and Gradle build to generate sonar test coverage report. But i found my test coverage is showing very low but in eclipse it is high. It is also showing all classes unsed src/test/java/** with zero coverage.
Please tell me how can i exclude all these test classes from output report also tell me how to exclude particular source java package from sonar -jacoco test coverage report. attaching screen shot.
Related
hi all i have build unit testing for controller, repository and Service but why in my sonarqube code coverage always give me code coverage only 0 percent. my question is how to make my percentage up ?
here what i was code in my testing
Sonarqube uses existing code coverage reports from JaCoCo (in the case of Java). Usually, you would set up the JaCoCo Maven plugin (or Gradle) to gather coverage info on test run and Sonarqube then loads this report.
See also the Sonarqube docs for info on setup. But if you are using Maven/Gradle, I believe Sonarqube is able to automatically pick up the correct file unless you have some special configuration.
We have a java project for which we are using jenkins.
In the build part we have configured jacoco as java agent to measure the code coverage.
If I download the created jacoco report and load it to IntelliJ all is fine.
But the sonar scanner also loads it up to the sonar server and there is something wrong with the analysis: Some classes and methods which are covered by tests (and I can see the coverage from the jacoco report in IntelliJ) are reported as uncovered by SonarQube.
Sonar Scanner definitly handles the right jacoco report.
Has anybody any idea where I should look for?
Is there anything in the sonar server which can led to a wrong coverage?
Thanks for any help!
sonar is not picking up the code coverage reports generated by IntellijIdea/Jacoco coverage reports.
Heres one sample of me trying to get sonar to pickup the jacoco report generated
Build Step:
Step 1
Ant
Build file path: junit-build.xml
Targets: default
JaCoCo coverage enabled
Execute: If all previous steps finished successfully
Step 2
SonarQube Runner
Execute: If all previous steps finished successfully
Artifact:
.teamcity
coverage_jacoco
jacoco.exec
UT JaCoCo Report: .teamcity/coverage_jacoco/jacoco.exec
JaCoCoSensor: JaCoCo report not found : /export/.../BuildAgent2/work/.../.teamcity/coverage_jacoco/jacoco.exec
Sonar:
This component does not have coverage details.
The issue is that the TeamCity jacoco runner places the output files in a temporary file location that can't be found by the sonar plugin or by sonar when run as a part of the maven/ant build. ".teamcity" is in the published artifacts store not the build area and before publishing the jacoco output appears to be in a randomly named directory.
The alternative is to turn off the teamcity jacoco runner and trigger the coverage and sonar scan via the maven or ant build itself. Sonar can be configured to find the results by putting the correct location in the administration->java->jacoco settings (relative to the build or module root) This will get your coverage into sonar.
To add the coverage report back into teamcity you need to add an artifact in your build general settings which collects the report html files into a coverage.zip file. Then you'll get a Code Coverage tab in your build results. (If you get two then you're still running the teamcity coverage runner as well.)
in short for maven builds (ant will be logically the same):
turn off the coverage option in the teamcity build step
add the org.jacoco:jacoco-maven-plugin:prepare-agent goal to create a report consumable by sonar
In sonarqube set the jacoco UT report to "target/jacoco.exec"
add the org.jacoco:jacoco-maven-plugin:report goal to create an html report for use by teamcity
add this artifact "target/site/jacoco/**/. => coverage.zip" to make the html report appear as a tab in teamcity
For multi-module builds where you have more than one report I can't find a way to get these into teamcity - though they do look fine in sonar. There is a jacoco merge goal that may help but I haven't been successful with it - and I suspect it'll mess up the sonar view.
Background:
I have 2 separate java projects, call them A and B.
Project A is the actual product (war application), with unit-tests. Gradle builds the project and then runs sonar analysis, and I can see the unit-tests coverage in Sonar.
Project B is an integration test for the first project. It is run by Jenkins in a pipeline after building project A and deploying it on an integration-environment. The deployment also involves instrumenting the code so that the jacoco-it report will correlate to Project A's classes.
My question:
How can I add to project A's sonar page, which currently has only unit-tests coverage, the integration tests coverage - as a second step?
The flow I need is:
build project A
run sonar analysis on project A (now it'll show unit-tests coverage on its sonar page)
build project B
run sonar analysis on project B - which will simply add integration-coverage to project A on sonar
It's currently not working. when I run sonar analysis on project B it messes up project A's sonar page, removing the unit-test coverage of A.
The flow that I have now, which is working but I want to change is:
build project A
run sonar analysis on project A
build project B
run jacoco report on project B. this outputs the jacoco-it.exec file into a specific location on my disk
run sonar analysis on project A (it has a setting to take the jacoco-it.exec file from the specified location
now project A's sonar page will show both unit-tests and integration-tests coverage, but step 5 is completely redundant and I want to avoid it.
Any suggestions?
what i will suggest is a bit different:
employ some build automation tool
create a sonar 'checker' job, which doesnt do the full analysis; just the incremental, this should break when add quality gate breaker issues
create a nightly job for your A project with full analysis: -Dsonar.analysis.mode=analysis (note: my experience shows that in this case you must run an incremental prior to this analysis, because in analysis mode sonar accepts new quality gate breaker issues
i don't think integration tests should count into project test coverage, so that might be just left out.
You cannot amend a previous analysis, which is why your 'B' job appears to replace the unit test numbers. What you need to do is generate your integration test coverage report before analysis, and make that report available so that both unit test and integration test numbers can be read in the same analysis.
From a build pipeline standpoint, that could get tricky depending on how you need to structure the jobs, but off-hand it sounds like you need 3 jobs:
build project A
build project B & generate integration test report
job 3 pulls integration test report from job 2, and either rebuilds project A or pulls code, classes, and unit test report from job 1 and performs analysis
How to turn off code coverage in SonarQube 4? I have JMockit usage in unit tests and JaCoCo code coverage plugin in Sonar. They conflict because they use different javaagents to edit bytecode of classes (as I know). I want to switch off code coverage in Sonar. I can exclude my project in settings of Jacoco, but it doesn't help.
I recommend following the paragraph "Ignore Code Coverage" in this documentation:
http://docs.sonarqube.org/display/SONAR/Narrowing+the+Focus