Publish Code Coverage in Jenkins

You will see how to generate generate and publish code coverage report in Jenkins CI using 3 simple additional steps.

  1. Enable the RKTracer tool and rebuild the application.
  2. Test instrumented application and save coverage data.
  3. Publish code coverage reports

Install the RKTracer code coverage tool plugin in Jenkins

1: Login into Jenkins.

Code Coverage tool integration in Jenkins step 1
Code Coverage tool integration in Jenkins step 1

2: On the right-hand side, the column selects Manage Jenkins and then manage plugins.

Code Coverage tool integration in Jenkins step 2
Code Coverage tool integration in Jenkins step 2

3: Go to the advanced tab and scroll down to the Upload plugin section.

Code Coverage tool integration in Jenkins step 3
Code Coverage tool integration in Jenkins step 3

4: Now browser and navigate to plugin section in RKTracer installation folder “C:\rktracer\share\rktracer-plugins” and select the “rktracer.hpi” file to upload.

Code Coverage tool integration in Jenkins step 4
Code Coverage tool integration in Jenkins step 4
Code Coverage tool integration in Jenkins step 5
Code Coverage tool integration in Jenkins step 5

5: After uploading, it takes some time to install and restart the Jenkins.

Code Coverage tool integration in Jenkins step 6
Code Coverage tool integration in Jenkins step 6

You have successfully configured rktracer code coverage tool plugin in Jenkins

Generate and Publish Code Coverage report in Jenkins

Enable the RKTracer tool

You need to enable RKTracer code coverage tool in project build job, as shown below.

MSBUILD/Dotnet

publish code coverage in Jenkins step 1
publish code coverage in Jenkins step 1
publish code coverage in Jenkins step 2
publish code coverage in Jenkins step 2

Build and Test the application

You can either trigger and run unit tests or integration tests or functional tests on rktracer code coverage tool instrumented application in Jenkins job.

Disable the RKTracer tool

publish code coverage in Jenkins step 3
publish code coverage in Jenkins step 3

Generate HTML and XML reports

XML report rktracer.xml is to publish reports in Jenkins

 XML report rktracer-sonarqube.xml to publish generic reports to sonarQube.

c:\rktracer\bin\rkresults.exe  -xml 

-xml : will generate xml coverage reports along with HTML reports.

publish code coverage in Jenkins step 4
publish code coverage in Jenkins step 4

Publish Code Coverage reports in Jenkins

You need to add “Publish RKTracer Coverage Reports” and don’t change the default setting.

publish code coverage in jenkins step 5
publish code coverage in Jenkins step 5
publish code coverage in Jenkins step 6
publish code coverage in Jenkins step 6

After build and testing the application, hit the refresh button on the browser. And now you will see the code coverage report

publish code coverage in Jenkins step 7
published code coverage reports in Jenkins step 7

Click on that code coverage, and you will see the code coverage data.

publish code coverage in Jenkins step 8
published code coverage reports in Jenkins step 8

Enable coverage for selected files

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 *.cpp

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

never */firmware_loader/* */lockdown/*

ignore *.cpp = Ignores all Cpp 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 *.cpp

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

function-ignore *

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

ignore *.cpp = Ignore all Cpp programming source files

instrument *file-X.cpp *file-Y.cpp *file-Z.cpp   = 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() = But instrument or don’t ignore these three functions from these three files.

Similar Posts