Jacoco in forked tests

(Shin Tai) #1


I’m using Jacoco which works out code coverage when running tests via a Java agent. Jacaco dumps its coverage data to a file when the process the agent is attached to terminates. This works quite well when running the ‘test’ task but when running in maxParallelForks mode the file is overwritten. Setting Jacoco to ‘append’ mode doesn’t seem to work either (I’m guessing file locking).

I can specify where Jacoco writes to, so does anyone know if it’s possible to separate out the jvmArgs for each Gradle worker that’s created?

This doesn’t work because it’s evaluated only once but hopefully it gives an idea of what I want to do:

test {
  jvmArgs "-javaagent:jacoco.jar=destfile=${buildDirName}/coverage-results/${System.getCurrentTimeMillis()}/jacoco.exec,append=false"

Then I’d be able to collect all the files and merge them into a report.

Jacoco has a server-client mode but that has its own problems too.

Thanks, Shin

(René Groeschke) #2

Hello Shin, Currently this is not possible, but you raised an interesting use case. I have to think a bit more about it if there is any workaround available atm.

cheers, René