Product
Solutions
Resources
Company
Download Trial Book a Demo

Publish Code Coverage in Azure DevOps

Generate and publish a code coverage report in Azure DevOps using three simple additional steps. Turn on the rktracer tool, run rkresults, convert the report to Cobertura, and publish it in your pipeline.

You will see how to generate and publish a code coverage report in Azure DevOps using three simple additional steps.

In short

Install the RKTracer plugin from the Azure Marketplace, then add the pipeline steps to disable Microsoft's auto-generated coverage, turn on rktracer, build and test, run rkresults in XML format, convert to Cobertura with reportgenerator, and publish the results.

Install the RKTracer plugin from the marketplace

The RKTracer should be installed with a valid license.

  1. To install the RKTracer plugin, go to the browser Azure Marketplace.
  2. Search rktracer in the search bar and install the RKTracer plugin.

You have successfully configured the RKTracer code coverage tool plugin in Azure DevOps.

Generate and publish the report in the 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.

azure-pipelines.yml
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.

azure-pipelines.yml
- script: rktracer -vs -on - *.sln
  displayName: "RKTracer ON"

Step 3: Build and test the application, that is, unit testing or functional testing.

Step 4: Generate RKTracer code coverage reports in XML format.

azure-pipelines.yml
- script: rkresults -xml -nolaunch
  displayName: "RKResults"

Step 5: Convert the RKTracer coverage reports to Cobertura format.

azure-pipelines.yml
- 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.

azure-pipelines.yml
- task: PublishCodeCoverageResults@1
  inputs:
    codeCoverageTool: 'Cobertura'
    summaryFileLocation: coveragereport/Cobertura.xml
    reportDirectory: coveragereport

Example RKTracer reports in Azure DevOps

You can see the test result in the test results view. 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.

Enable coverage for selected files

You can scope coverage to specific folders, files, or functions by editing rktracer.config in the RKTracer installation folder.

Coverage reports for selected folders

For example, given folders such as:

example 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, that is, core, keys, power, and you want to ignore coverage for the folders firmware_loader and lockdown. Edit rktracer.config in the RKTracer installation folder, go to the end of the file, and add the following information.

rktracer.config
ignore *.cpp
instrument */power/* */core/* */keys/*
never */firmware_loader/* */lockdown/*
  • ignore *.cpp ignores all Cpp source files from instrumentation.
  • instrument instruments source files from the given folders.
  • never ignores the selected folder.

Coverage reports for selected functions

For example, to generate coverage only for selected functions from three different files:

selected functions
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, go to the end of the file, and set the following variables as shown below.

rktracer.config
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 ignores all Cpp programming source files.
  • instrument *file-X.cpp *file-Y.cpp *file-Z.cpp instruments only these three source files.
  • function-ignore * then ignores all functions in the above three files.
  • function-instrument fun_X() fun_Y() fun_Z() instruments, or does not ignore, these three functions from these three files.

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.