Getting code coverage of my application using JaCoCo Java agent on Tomcat

前端 未结 3 1377
星月不相逢
星月不相逢 2020-12-31 10:05

I want to measure the code coverage of integration tests using the JaCoCo and Sonar tools.

For that, I start my Tomcat 5.5 configured with the JaCoCo agent in order

3条回答
  •  星月不相逢
    2020-12-31 10:43

    Besides the maven solution, you can also consider https://www.eclemma.org/jacoco/trunk/doc/cli.html

    Basically, you start your service on the remote machine with the javaagent option like (you can change the port number and omit includes if you want to have coverage for all of the classes):

    -javaagent:/tmp/jacocoagent.jar=port=36320,destfile=jacoco-it.exec,output=tcpserver,includes=a.b.c.d.*”

    Then connect to the remote machine by providing remote host address or open a tunnel to the remote machine. The following example assumes I have set up a port forwarding between local host's 36320 and remote host's 36320

    java -jar jacococli.jar dump --port 36320 --destfile /tmp/jacoco-it.exec

    If you have multiple .exec files, you need to merge them:

    java -jar jacococli.jar merge /tmp/jacoco-it-1.exec /tmp/jacoco-it-2.exec --destfile /tmp/merge

    Then generate the html report (path1 can be a path to the jar file or the class files folder)

    java -jar jacococli.jar report /tmp/jacoco-it.exec --classfiles path1 --sourcefiles path2 --html /tmp/report

提交回复
热议问题