You didn't mention what language your application was written in. However, I have a good quick solution for anyone coming across this question for a Java application.
JaCoCo Java agent
I'll be using the JaCoCo test coverage tool. Specifically it's java agent.
First go to the JaCoCo github releases page to download the zip of the latest release. Once downloaded, extract the zip and find the jacoco.jar file. A quick example script:
find -name 'jacocoagent.jar'
Note the location of the output file (for me it was in
In the JaCoCo java agent it specifies that you need to run the java agent like so:
In our case you'll be running your application with something like this:
java -javaagent:lib/jacocoagent.jar=destfile=test.exec [...]
Then the rest of your
java commands (
You can also optionally specify the
append=false java agent option if you want to overwrite your test coverage results.
Run your application with the
java command specified above and then run your tests against it. Once the tests are finished it's important to shut down the application before accessing your
test.exec file. The `test.exec file is written to when the application exits. See the java agent docs for more information.
JaCoCo reporting with Gradle
I'm not familiar of a more generic way of running JaCoCo (though I do believe it has a CLI tool) so I'm going to wrap this up with a gradle example.
First, make sure that you change the above agent option to
destdir=build/jacoco/test.exec as this is the default location where the 'jacoco' plugin looks for your coverage data file.
In order to generate your test coverage reports, add the 'jacoco' plugin to your to your
build.gradle file then run the
jacocoTestReport gradle task (e.g.
./gradlew jacocoTestReport if you're using gradlew). You can view your test coverage in your browser by navigating to
build/reports/jacoco/test/html/index.html relative to your project root.
I've used this before for E2E testing but I can see it being useful in other situations like seeing what code is being run during exploratory testing.