Olcay Tarazan
Olcay Tarazan

Reputation: 961

Manuel Tests Code coverage on Sonarqube

I would like to get code coverage using JaCoCo and display it on Sonarqube after several manual and automated End-to-End tests. Currently, we can also collect JUnit tests coverage which is triggered during mvn test

It looks like I need to instrument the code on JVM using Jacoco Agent. But I need some examples to this. First of all, I need to know where can I get Jacoco agents?

Upvotes: 0

Views: 953

Answers (1)

Gerald Mücke
Gerald Mücke

Reputation: 11132

When you have maven already up and running, watch it's output. Jacoco prepares an argument line for surefire that contains a pointer to the agent:

[INFO] --- jacoco-maven-plugin:0.7.5.201505241946:prepare-agent (pre-unit-test) @ examples ---
[INFO] jacoco.surefireArgLine set to -javaagent:E:\\mvnrepository\\org\\jacoco\\org.jacoco.agent\\0.7.5.201505241946\\org.jacoco.agent-0.7.5.201505241946-runtime.jar=destfile=E:\\examples\\target\\jacoco-ut.exec,append=true,includes=org.example.*

The generated argline is basically the same as you may use for the JVM you want to generate coverage data for:

-javaagent:E:\\mvnrepository\\org\\jacoco\\org.jacoco.agent\\0.7.5.201505241946\\org.jacoco.agent-0.7.5.201505241946-runtime.jar=destfile=E:\\example\\target\\jacoco-ut.exec,append=true,includes=org.example.*

After you've done with the manual tests you have to re-run sonar analysis to pick up the unit test results. Note that the destfile in the argline must point to a location in your maven structure.

Upvotes: 3

Related Questions