You will see how to generate and publish a code coverage report in Azure DevOps using three simple additional steps.
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.
- To install the RKTracer plugin, go to the browser Azure Marketplace.
- Search
rktracerin 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.
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, that is, 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
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:
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.
ignore *.cpp instrument */power/* */core/* */keys/* never */firmware_loader/* */lockdown/*
ignore *.cppignores all Cpp source files from instrumentation.instrumentinstruments source files from the given folders.neverignores the selected folder.
Coverage reports for selected functions
For example, to generate coverage 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, 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 *.cppignores all Cpp programming source files.instrument *file-X.cpp *file-Y.cpp *file-Z.cppinstruments 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.