Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jacoco code coverage for remote machine

Tags:

rest

maven

jacoco

I tried to find this answer but hardly found it anywhere. I am doing the API testing, In process I need to call the rest API from my local machine. local machine contains the maven project and a framework to call respective rest API.

I need to check the code coverage of remote Rest API and form a report based on the code coverage. please help, how to do that?

Note: I found this link useful but it does not elaborate clearly on what to do?

http://eclemma.org/jacoco/trunk/doc/agent.html

like image 643
atul tripathi Avatar asked Oct 20 '22 00:10

atul tripathi


1 Answers

you will probably do a bit of file copying around - depending on the way you run the tests.

JaCoCo runs as a java agent. So you usually add the javaagent parameter as mentioned in the docs you linked to the start script of you application server.

-javaagent:[yourpath/]jacocoagent.jar=[option1]=[value1],[option2]=[value2]

so it would look like:

java -javaagent: -jar myjar.jar

Using tomcat you can add the "-javaagent" part into JAVA_OPTS or CATALINA_OPTS environment variables. Should be similar for other servers.

this will create the jacoco*.exec files. you need to copy those back to your build or CI server to show its results (for ex if you use sonar you need those files before running the sonar reporter). Its important to just include the packages you're interested in.

You can also create one jacoco.exec file per test flavour (jacoco.exec for unit tests, jacoco-it.exec for integration tests, jacoco-at.exec for application tests).

And I would not mix coverage with performance testing - just to mention that too.

There are some examples on stackoverflow for JBoss

like image 142
wemu Avatar answered Oct 21 '22 17:10

wemu