I have integrated Jacoco to a maven project.
When computing coverage for a particular class, the report shows code coverage percentage for each method in that class as close to 40% - 50% even though the coverage is 100%. This is the case with multiple other java classes as well.
Any idea as to why this happens? Appreciate your help to solve this.
Related
I run a Unit test with coverage, and get the Coverage list.
The list contains the class that I am testing, and also classes that I have not tested. See picture below.
Is it a way to automatically hide classes that is not tested?
At the moment of writing this answer (Intellij Idea 2019.3 and Bundled Coverage Plugin), there is no such option.
Below are the only available configurations of Coverage Plugin.
I see that the build-in code coverage in Intellij is pretty minimal (only include line coverage, and not branch coverage).
What are the recommended code coverage libraries to work with IntelliJ?
(I used to work with Jacoco in Eclipse).
The IntelliJ IDEA code coverage runner provides branch coverage.
Tracing mode enables accurate collection of the branch coverage, with the ability to track tests, view coverage statistic, and get additional information on each covered line.
(From the docs)
To engage this, open the Edit Run/Debug Configuration dialog box for your test run and click on the Code Coverage tab. Then ...
Chose coverage runner: IntelliJ IDEA
Click on Tracing (instead of the default: Sampling)
Run your test and then click into the class from the Coverage Window and you'll see branch information in the side bar.
Here's a screenshot:
We have a single evosuite generated unittest .java file. We have other hand-crafted unittest .java files. We execute a build on our server and all unittests (evosuite and hand-crafted) are executed. We then go into our sonar dashboard and specifically look at the coverage. There is coverage reported by sonar/jacoco from the handcrafted unittests. However for the .java file that the evosuite was to test, that file still has 0% coverage even though on another panel in the sonar/jacoco dashboard the evosuite 16 tests were executed and it shows how long in ms they took.
The server where the builds take place was configured for us and we do not manage them. Sonar/Jacoco admin setup was done by others.
I'm at a loss as to why our handcrafted ones (some use #RunWith(JMockit.class) and some don't use a RunWith annotation) show up w/ coverage percentages and the evosuite does not.
Thanks,
Jim
yes, that is an issue that has been reported few times now... so I just added now some documentation about it :-) at:
http://www.evosuite.org/documentation/measuring-code-coverage/
you can read there why you get 0% coverage, and possible workarounds for it.
As discussed in Open JaCoCo report in Intellij IDEA, when I gather code coverage statistics using Jacoco (rather than native IntelliJ tracing) 0.0% (i.e. "no" coverage) is always shown in the coverage window.
This is after I have done the whole "Analyze -> Show coverage data..." and selected my generated "jacoco.exec" file.
The same "jacoco.exec" file works fine with other tools such as the Jacoco native report generation task, and with Sonar, and these produce the expected coverage report content.
Also native IntelliJ instrumentation works fine.
Can anybody advise me if there is some essential step I must perform to get IntelliJ to accept my Jacoco coverage?
When you add the class to PowerMockito annotation #PrepareForTest for the test classes, the corresponding class will not be showing the code coverage.
Buid source code through IntelliJ before importing jacoco.exec might be solved this showing 0% coverage problem.
For me the solution was to simply add the root package (in my case "de" in your case probably "com") to the "Packages and classes to include in coverage data".
Now i see a reasonable Code Coverage.
I may guess you are trying to see test coverage in same way as it is show by the TeamCity(jaCoCo).
If Yes there are simple workaround how to check all missed branches(just general statistic which branches was visited and how many times) :
That's all my advices , folks
"intellij idea" seems to have no way of showing correct coverage value of jacoco report created. It is indeed misleading and unfair when it shows coverage as 0.0 instead of giving an unsupport format error.
However, as an alternative, we can push jacoco report (created as part of maven build) to the sonar(qube) server using maven-sonar-plugin's target, sonar:sonar
mvn clean install sonar:sonar -Dsonar.host.url=http://<sonar-host>:9000 -Dsonar.projectKey=<sonar project key> -Dsonar.branch=<sonar project branch> -Dsonar.login=<sonar user> -Dsonar.password=<sonar pwd>
sonar.projectKey and sonar.branch properties value can be retrieved from corresponding project created in sonarqube.
I am looking for a code coverage tool, which helps me find coverage of selected packages in my workspace.
Solution pertaining to CI or Eclipse is welcome.
I am aware that, I can manually calculate based off the numbers I get from code coverage tools in eclipse. But I am reluctant to do so and want to rely on automatically computed code coverage.
Please help.
You could try the google CodePro,
Reference : https://developers.google.com/java-dev-tools/codepro/doc/features/codecoverage/code_coverage