Product
Solutions
Resources
Company
Download Trial Book a Demo

Code Coverage for Gradle build Java Applications

Generate code coverage for a Gradle build Java application with RKTracer. Enable the tool with rktracer gradle -on build.gradle, rebuild, run your tests, produce an HTML report with rkresults, then disable the tool.

You need to build and test the application with gradle build. The RKTracer tool will automatically add a runtime library to the application when you integrate and build the application with the RKTracer tool.

In short

Enable RKTracer with rktracer gradle -on build.gradle, run gradle rebuild, run your tests, generate the HTML report with rkresults, then disable with rktracer gradle -off build.gradle.

Enable RKTracer Tool

To instrument with the RKTracer tool, you need to enable RKTracer before running the gradle build command to build the application. You should always rebuild the project to instrument the application with the RKTracer tool.

The RKTracer tool makes internal adjustments to the gradle build to instrument all the source files compiled at build time. By default, rktracer instruments for multiple-condition code coverage.

enable and rebuild
gradle build
rktracer gradle -on build.gradle
gradle rebuild

Run tests on instrumented application

When executing unit or functional tests, the RKTracer tool will save coverage data to the rk-coverage.txt file on the host or phone device.

For device testing, you can pull the coverage data:

pull coverage data from device
adb pull /data/data/com.example.widecolor/rk-coverage.txt

Generate Code Coverage HTML reports

After obtaining the rk-coverage.txt file, run rkresults against your build.gradle file.

generate the report
# Linux
rkresults app/build.gradle

# Windows
rkresults app\build.gradle

The reports are generated in project folder/rktracer/reports/ and can be accessed via index.html.

Disable the tool when done

Once the reports are generated, you need to disable the RKTracer tool with rktracer gradle -off build.gradle.

Enable coverage for selected files

Edit rktracer.config and add directives to scope coverage to specific folders, files, or functions.

rktracer.config
ignore *.java
instrument */power/* */core/* */keys/*
never */firmware_loader/* */lockdown/*

Alternatively, target specific functions:

rktracer.config
function-ignore *
function-instrument fun_X() fun_Y() fun_Z()

Next steps

Once your Gradle build reports coverage, the same RKTracer workflow applies across other build systems and IDEs. Browse the rest of the documentation, or read more about how RKTracer measures coverage through MC/DC.

Stuck on your build?

Open a support ticket and an engineer who knows your toolchain will help. You get a tracked ticket ID by email.