DotCover Cobertura or OpenCover XML - code-coverage

I have a dotcover coverage report generated using dotcover.exe.
I want to integrate the report in Jenkins and show the coverage.
How can I generate a cobertura or openclover xml from it?

You can use ReportGenerator for that.
First, install reportgenerator as dotnet global tool:
dotnet tool install --global dotnet-reportgenerator-globaltool
Second, dotCover report should be in DetailedXML format, it has file paths that needed in Cobertura.
Then, run reportgenerator to convert to desired format, like:
reportgenerator -reports:./dotCover.Output.xml -targetdir:. -reporttypes:Cobertura
As a result, you'll have Cobertura.xml file.

Related

Bazel's Java lcov report uses package instead of file paths

I am collecting code coverage for a Java-based repository using the following command:
bazel coverage --jobs=$PARALLEL_JOBS --keep_going --flaky_test_attempts=3 --cache_test_results=no --combined_report=lcov --coverage_report_generator="#bazel_tools//tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator:Main" -- //$TARGET/...
This creates a coverage report in this directory:
$(bazel info output_path)/_coverage/_coverage_report.dat
Problem: All of the files reported in this coverage report correspond to Java packages instead of actual files (e.g. com/my_package/path/my_class.java)
Question: How do I configure bazel coverage to report coverage data by original source files instead of Java packages?
I would like to post process these coverage files, but I don't have a clear way to map all of these Java packages into original source files.
Thank you!

Bazel: How to exclude path from code coverage for Scala / Java?

I am using Bazel with rules_scala. My problem now is how to exclude files from code coverage. So far this is how I am running coverage:
rm -rf coverage
bazel coverage --combined_report=lcov --coverage_report_generator="#bazel_tools//tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator:Main" ...
genhtml -o coverage --ignore-errors source bazel-out/_coverage/_coverage_report.dat
But there are some folders I would like to exclude from code coverage. I tried using the --instrumentation_filter flag, but no matter what I tried putting there Bazel still collect coverage for this folder.
Are there any examples how I should use this flag?
Thanks!
Use
bazel coverage --combined_report=lcov --coverage_report_generator="#bazel_tools//tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator:Main" -- //... -//package/to/ignore/...
This appears to be a bug with rules_scala. See this issue for more details.

Export Jacoco's coverage report in XML format to Jenkins

I have a multi-module project and I am using JaCoCo plugin to generate coverage reports. I followed this blog to create a new module(let's call it project-coverage) and then added the dependencies there and then use the report-aggregate goal of jacoco to create the aggregated report.
At the end of the build I have an XML file under project-coverage/target/site/jacoco-aggregate/jacoco.xml
How can I take this XML and export it into Jenkins? I know there is a plugin support for Jacoco in Jenkins but I am not sure how can I use this XML report and not exec files to report the coverage in Jenkins.
I know there is a plugin support for Jacoco in Jenkins but I am not sure how can I use this XML report and not exec files to report the coverage in Jenkins.
According to https://www.jacoco.org/jacoco/trunk/doc/integrations.html there are at least two plugins for Jenkins. And according to the documentation of these plugins
https://plugins.jenkins.io/jacoco/ consumes exec
https://plugins.jenkins.io/code-coverage-api/ consumes XML

How to integrate Jacoco report in Sonarqube

I'm using Jenkins+Jacoco+Sonarqube to test my code. In Jenkins, my mvn command is:
mvn clean install sonar:sonar.
After code build in Jenkins, I am able to see the code coverage in Jenkins.
But I cannot get proper coverage percentage in SonarQube.
This could be a source path issue, maybe you don’t analyze the same sources. Do you have any excluded source files in Jacoco and Jenkins that you didn’t exclude in SonarQube properties, or vice versa?
Your command doesn't include the generation of the reports. Try instead:
mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install sonar:sonar
Breaking it down:
mvn invoke the build system
clean delete all old build output
org.jacoco:jacoco-maven-plugin:prepare-agent turn on test reporting
install build and install the result in the local Maven repository
sonar:sonar run a SonarQube analysis

Is it must to point source files for jacoco report generation

I have created jacoco.exec file by setting -javaagent as jvm option in my server startup script. Now I want to generate coverage report using the coverage exec file.
I've gone though all Jacoco report generation options (maven, ant, API etc..) However all these options required to have source class files. I'm trying to generate coverage for set of jar files where as sources files are not available. In that case, is there a workaround to achieve coverage generation.
Yes, you can generate report without source code, I also generated the exec file by setting the option in server startup script, then I got the exec file and generated the report in eclipse using eclemma code coverage plugin.

Resources