I generated a code coverage report from jacoco, which is jacoco.exec. But I don\'t know how to use it ...
The way I generated it is through command line:
I think the report will have already been generated. Look in the folder target/site/jacoco
.
This provides target/site/jacoco/jacoco.csv
, which is some raw text that you can interpret relatively easily -- maybe import into a spreadsheet
Most people will want target/site/jacoco/index.html
, which is a report in web-page form.
If you aren't seeing these reports, try explicitly requesting them and see if any clues are provided...
mvn clean test jacoco:report
In IntelliJ Idea from the menu select Analyze
> Show Coverage data
. In the new window press the + button and select your .exec file.
The test coverage results will appear in the editor Coverage tab.
In the latest version of Intellij Idea the menu has been moved to Run
> Show Code Coverage Data
terminal: mvn install jacoco:report for maven project with jacoco plugins
Jacoco provides a command line lib to process jacoco.exec
data: Jacoco cli doc
After you install Jacoco, you can generate report with following command:
java -jar lib/jacococli.jar report jacoco.exec \
--html ./report \
--sourcefiles [path/to/your/source/files] \
--classfiles [path/to/your/class/files]
To view this in IntelliJ Idea, from the menu bar, select Run > Show Code Coverage Data. In the new window (Choose Coverage Suite to Display), press the + button and select your .exec file. The test coverage results will appear in the editor Coverage tab.
To generate the Coverage Report files for the above .exec file, select Run > Generate Coverage Report. Then select your output directory and click on Save. Your reports would be generated to the selected folder. Open the index.html file in the folder to view the results on the browser. I am using IntelliJ IDEA 2019.3.4 (Community Edition)
we can push jacoco exec 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://:9000 -Dsonar.projectKey= -Dsonar.branch= -Dsonar.login= -Dsonar.password=
sonar.projectKey and sonar.branch properties value can be retrieved from corresponding project created in sonarqube.