kfan
kfan

Reputation: 46

How to get jacoco instrumentation with a play project for external functional testing?

I am using IntelliJ Idea to develop a java service with APIs using the Play Framework 2.3. I have jacoco instrumentation set up for our unit tests on the command line using the jacoco4sbt plugin. I can get code coverage by running sbt jacoco:cover to generate a coverage report. I am trying to get coverage for the service while it is running so that I can use an external client (such as my browser) to test the APIs and get coverage. How can I do this either through the command line with sbt or through IntelliJ Idea?

I have tried using javaagent:/Users/kfan/jacoco/lib/jacocoagent.jar=destfile=jacocoRun.exec,append=false in my jvm options for the project in IntelliJ, which seems to generate a report file, but it gives me 0% coverage on everything, which should not be the case.

Any help would be appreciated!

Upvotes: 1

Views: 698

Answers (1)

kfan
kfan

Reputation: 46

I ended up using the java agent from the command line to instrument the test. I used

sbt run -J-javaagent:/Users/kfan/jacoco/lib/jacocoagent.jar=destfile=target/jacoco/jacoco.exec,append=true

in order to get an instrumented version running. From there, I just need to execute my tests and stop the server gracefully (kill -15 [PID]) to get the exec file correctly. From there, using the target sbt jacoco:report generated a report from the resulting file.

Upvotes: 1

Related Questions