how to use jacoco.exec report

前端 未结 10 1327
感情败类
感情败类 2020-12-07 18:30

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:

相关标签:
10条回答
  • 2020-12-07 19:03

    Per this thread you can't use your generated jacoco.exec directly to produce a report. You can download Jacoco's sample build.xml and use it to produce a report, instead. You'll need to make these changes to build.xml: set the the paths to

    • your downloaded jacocoant.jar
    • your jacoco.exec
    • your project source code
    • your compiled project class files

    I also changed the default target to "report". Then run it by typing "ant" and your reports will be generated.

    0 讨论(0)
  • 2020-12-07 19:08

    If you use maven, use the report-aggregate goal.

    See link below:

    report aggregate maven goal

    This is a snippet from my maven pom.xml file

                <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.2</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>report-aggregate</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions
    

    The csv report file was generated under: site/jacoco/jacoco.csv

    0 讨论(0)
  • 2020-12-07 19:09

    For Eclipse users, you can simply use EclEmma jacoco plugin in Eclipse. Window > Show View > Coverage (of course you must install the plugin first). In the Coverage window, Right click > Import >..... Select the exec file (or other nice methods), select your source code, then see. You can also export the result to html file.

    0 讨论(0)
  • 2020-12-07 19:15

    This answer would be similar to @Evans Y. One can generate HTML files (over here in report directory) and XML file (named as cov) with the help of below command from Jacoco documentation.

    java -jar lib/jacococli.jar report jacoco.exec \
    --classfiles C:\Users\severalOtherDirectories\YourProject\target\classes \
    --html ./report --xml cov.xml
    

    HTML Report: This report would be able to show total number of lines covered/uncovered at the Class or method level, but won't be able to show what actual line(s) are covered/uncovered in the same.

    XML file: After plugging this generated file in the project and simply using VS code coverage extension (I prefer coverage gutters) , one can visualize line-by-line status in the editor itself.

    0 讨论(0)
提交回复
热议问题