How Can We Help?
< All Topics
Print

Integrate RKTracer with Maven build and generate code coverage

You need to build and test the application with maven build. Ensure maven installation in the system path. To generate code coverage for the Maven-based application in Windows and Linux, you need to prefix rktracer to the maven build command.

 mvn clean test

  TO

 rktracer -v mvn  clean test

 

RKTracer tool makes internal adjustments to maven build to instrument all the source files compiled in build. By default, rktracer instruments for multiple-condition code coverage, and you see the following code coverage information in the HTML report.

  • Function Coverage
  • Line Coverage 
  • Statement Coverage
  • Multi-Condition Code Coverage

Example Maven build

Step 1: Enable RKTracer tool and rebuild application.

mvn clean test

TO

rktracer -v mvn clean test 

  Text Description automatically generated

  • RKTracer instruments the java source file with “c:\rktracer/lib/librklij-x86_64-w64-mingw32.exe ” and writes the instrumented file to the “prime.java” file in the preprocessed directory. Also, it stores the metadata, structure of instrumentation, and copy of source file content in JSON file. The tool will refer to rktracer.config for internal configuration at the time of instrumentation.
  • RKTracer automatically adds runtime library to Maven installation.
 

Step 2: Test instrumented application. 

You can do unit testing/functional testing on the instrumented applications. In this case, it’s unit testing.

Text Description automatically generated

Post-testing the RKTracer tool will save coverage data to the rk-coverage.txt file.

Step 3: Generate Code Coverage HTML reports.

Once you have the rk-coverage.txt file, you can run the command “rkresults” to generate HTML reports in the application working directory. Ensure that you run the “rkresults” command in the application root folder or where we have the “rktracer” folder.

Graphical user interface, text Description automatically generated

rkresults command will search coverage data file “rk-coverage.txt” and map with JSON files (generated during instrumentation) in the rktracer folder and generate an Html report. 

You can manually open the HTML report using index.html.

Graphical user interface, text, application, email Description automatically generated

Generate code coverage for selected functions/files/folder

Generate coverage reports  for the selected folders

C:\project\sound\drivers\base\power\

C:\project\sound\drivers\base\power\firmware_loader\

C:\project\sound\drivers\core\

C:\project\sound\security\keys\

C:\project\sound\security\lockdown\

Suppose you need code coverage for source files from three different folders, i.e., core, keys, power, and ignore coverage for folders firmware_loader and lockdown. Edit rktracer.config in the RKTracer installation folder and go to the end of the file add the following information. 

ignore *.java

instrument */power/* */core/* */keys/*

never */firmware_loader/* */lockdown/*

 

ignore *.java = Ignores all Java source files from instrumentation

Instrument = Instrument source files from given folders

never = ignore selected folder  

        

Generate coverage reports only for selected functions from three different files.

fun_X() in source-file-X 

fun_Y() in source-file-Y

fun_Z() in source-file-Z

Suppose you need code coverage for selected functions from three different files. Edit rktracer.config in the RKTracer installation folder and go to the end of the file and set the following variables as shown below.  

ignore *.java

instrument *source-file-X.java *source-file-Y.java *source-file-Z.java

function-ignore *

function-instrument fun_X() fun_Y() fun_Z()

 

ignore *.java = Ignore all Java programming source files

instrument *file-X.java *file-Y.java *file-Z.java  = Instrument only these three source files.

function-ignore * = Then ignore all functions in the above three files.

function-instrument fun_X() fun_Y() fun_Z() = Don’t ignore these three functions from these three files from instrumentation.


Previous Code Coverage for Java/Kotlin Apps in Android Studio IDE
Next Code Coverage for Selenium java web application Eclipse IDE
Table of Contents