SonarQube calculates wrong code coverage from jacoco result - java

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!

Related

Cannot use Jacoco in IntelliJ IDEA

In my Java app, in order to generate coverage reports for my Unit Tests, I have tried several approaches to setup Jacoco as in Run with coverage or this page. However, I cannot generate coverage reports as expected and I think I need some steps describing the setup of Jacoco on IntelliJ. So, does anybody else have experience for setup and run it via command line as shown below:
mvn --global-settings ../settings.xml
-Dtest="/com/mycompany/core/service/impl/unit/ProductServiceImplTest.java" test
Any help would be appreciated.

my sonarqube always said no code coverage for java

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.

How to exclude Sonar test classes from test coverage report

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.

Integrate Spock's test with Sonar

I use spock to write test case and jenkins to run and publish my test cases.
I was able to get the code coverage reported but sonar shows me only Java Unit test cases; the groovy test cases are totally missing
The following pom.xml is used as reference
https://github.com/kkapelon/java-testing-with-spock/blob/master/chapter7/spring-standalone-swing/pom.xml
would anyone please know what I am missing ?
Install the Groovy plugin in Sonar. Login as admin/admin and go to
the administration/system/update-center tab
Add the following property in the
pom file
<sonar.tests>src/test/groovy,src/test/java</sonar.tests>
If you do this both Spock and JUnit tests are shown correctly!
See attached screenshot

Using Sonar in Ant only for code coverage with JaCoCo (no static analysis)

I created a job in Jenkins that executes sonnar-runner against all the projects in my repository. This job is independent from code coverage and runs a few times a day.
On the other hand, I want code coverage to happen upon a build (using JaCoCo) and import the reports into Sonar using Ant.
I set up my environment and added the JaCoCo and Sonar plug-ins to the Ant lib directory. When I run the Ant target I can see the results of JaCoCo locally in XML and HTML.
All I want is to upload these results to a remote SonarQube instance. However, after setting up the Sonar properties and adding <sonar:sonar> to my build.xml I realized that Sonar seems to be running static analysis against my project.
How do I set up Ant to only run code coverage for a project?
You can't run only a small portion of the full analysis.
Imagine for a moment that this were possible: Let's say that once an hour a "coverage only" job runs that updates the coverage on my project.
At 8 a.m. I start with a project with 6 LoC and 50% coverage.
At 9 a.m. my project has "6 LoC" and 20% coverage
10a.m.: "6 Loc" and 10% coverage.
Has someone been removing tests? Or adding new, uncovered LoC?
I have no way of knowing because my partial analysis has put the SonarQube project in a bad state.
And this is why there's no way to run only part of the analysis.

Categories

Resources