Ashish Ranjan Sinha
Ashish Ranjan Sinha

Reputation: 1

Can't generate jacoco.exec file with javaagent

I am using java agent for generating the code coverage for integration tests which is separated from the application under test and those test use external interface exposed by that application. I have executing java -javaagent:<path_to_jacocoagent>=destfile= .The idea here is to use a parameter A_RUNJAVA_EXTRA_VM_ARGS="javagent:<path_to_jacocoagent>jacocoagent.jar=destfile=jacoco.exec" where javaagent specifies the location of the jacocoagent.jar and destfile represents the place to put jacoco.exec. I am restarting my VM using a script on Jenkins and running the junits via jenkins. Even after the Junit test summary is generated, i donot see jacoco.exec file to be generated.

need some advice on what went wrong.

I have tried almost everything from my end. One thing which I believe can be the cause is jacoco agent not loaded properly by the java process becz when i use ps aux | grep java I donot get any output after the restart of the vm occures

Upvotes: 0

Views: 137

Answers (1)

Vera Stoyanova
Vera Stoyanova

Reputation: 1

I know it might be very late 4 months later, but here is some comment from me: Whatever environment variables into the OS you are specifying, this does not mean that the java process when started gets to "see" them.

You need to actually track the place which really starts the java process which you need JACOCO-ed and add the -javaagent to this very process's VM arguments.

It might be a batch file, or an EXE which triggers the VM somehow but it gets configured with an INI file, or the VM process could be started from within another piece of source code, i.e. you might need to dig into who actually starts the VM into the Jenkins job.

If this process allows you to somehow override or influence the vm arguments from a command line or an environment variable, then you will have a more elegant solution. The very ugly solution would be to just "SED", i.e. replace the original VM invocation into the very BAT, CMD, SH, modifying it to include your -javaagent.

And one more thing: The jacoco.exec files are being written at the "exit" of the VM, i.e. when the Application Under Test is getting stopped. I.e. the end of the execution of the Unit tests does not have any influence on the jacoco files. The stopping of the Java Process of the Application Under Test does.

Upvotes: 0

Related Questions