how to use Jacoco when running embedded tomcat8.5

42 views
Skip to first unread message

FEI YANG

unread,
Oct 25, 2016, 10:28:04 PM10/25/16
to JaCoCo and EclEmma Users
I'm new to use Jacoco to get restapi testing codecoverage of my java webapp project.
The way I run my webapp project:
  1) use gradle to add embedded tomcat dependencies
  2) create a Main function to run tomcat(version8.5) like this: https://devcenter.heroku.com/articles/create-a-java-web-application-using-embedded-tomcat#deploy-to-heroku
  3) use gradle to create a jar file
  4) java -jar xxx.jar in other place(wanna to deploy to aws)
now after run jar file, tomcat start runing and api response is ok

I also wrote sample test code using rest-assure
in this situation how could I use jacoco to coverage code when running the jar file?

I tried add -javaagent like this:
    java -javaagent:jacocoagent.jar=classdumpdir=dump -jar xxx.jar

  when I stopped run using ctrl-c, java class files dumped into dump folder and a jacoco.exec file created but 0 bytes...

please help me..
お願いします。
帮帮忙。。
  

Evgeny Mandrikov

unread,
Oct 26, 2016, 7:21:25 AM10/26/16
to JaCoCo and EclEmma Users
JaCoCo creates an empty file at startup to ensure that location is writable.
I doubt that termination of Tomcat by Ctrl-C results in graceful JVM termination, and thus doubt that hook is executed. So please make sure that you gracefully terminate JVM.
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages