Publish Code Coverage in Azure DevOps

You will see how to generate generate and publish code coverage report in Azure Devops 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 Azure Devops from marketplace

The RKTracer should be installed with a valid license.

1: To install the rktracer plugin. Go to the browser azure marketplace.

Install rktracer code coverage plugin azure Devops from marketplace step 1
Install rktracer code coverage plugin azure Devops from marketplace step 1

2: Search rktracer in the search bar and install the RKTracer plugin.

Install rktracer code coverage plugin azure Devops from marketplace step 2
Install rktracer code coverage plugin azure Devops from marketplace step 2

You have successfully configured rktracer code coverage tool plugin in Azure Devops

Generate and Publish Code Coverage report in Azure DevOps Pipeline

Edit the project pipeline in Azure DevOps, and you need to make the following changes.

Step 1: You need to disable the auto-generated code coverage by Microsoft.  

variables:

  – name: disable.coverage.autogenerate

    value: ‘true’

 

Step 2: Before you build your project, make sure you have turned on the RKTracer tool.

For example, in a visual studio.

– script: rktracer -vs -on – *.sln

  displayName: “RKTracer ON”

 

Step 3: Build and Test the Application, i.e., unit testing or functional testing.

Step 4: Generate RKTracer Code Coverage reports in XML format.

– script: rkresults -xml -nolaunch 

  displayName: “RKResults”

 

Step 5: Convert the RKTracer Coverage Reports to Cobertura format.

– task: reportgenerator@4

  inputs:

    reports: ‘**/rktracer.xml’

    targetdir: ‘coveragereport’

    reporttypes: ‘Cobertura;RKHtml;’

    verbosity: Verbose 

 

Step 6: Publish Code Coverage Reports in Azure DevOps using the following task.

– task: PublishCodeCoverageResults@1

  inputs:

    codeCoverageTool: ‘Cobertura’

    summaryFileLocation: coveragereport/Cobertura.xml

    reportDirectory: coveragereport

Example RKTracer Reports in Azure DevOps

Code Coverage Report in Azure Devops pipeline step 1
Code Coverage Report in Azure Devops pipeline step 1

You can see the test result as shown in the following screenshot.

Code Coverage Report in Azure Devops pipeline step 2
Code Coverage Report in Azure Devops pipeline step 2

You can also see the code coverage summary report in the code coverage section. You can see different  Code Coverage Metrics like Line Coverage, Statement coverage, and Multiple Condition Coverage.

Code Coverage Report in Azure Devops pipeline step 3
Code Coverage Report in Azure Devops pipeline step 3

Enable coverage for selected files

Generate coverage reports  for the selected folders

C:projectsounddriversbasepower

C:projectsounddriversbasepowerfirmware_loader

C:projectsounddriverscore

C:projectsoundsecuritykeys

C:projectsoundsecuritylockdown

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