Recording unit test code coverage

It is a best practice to not only run all unit tests during the build but to also determine the percentage of the code base that was executed during any of these tests. This is called unit test code coverage and is an indication of how thorough the tests are. The build can also be configured to publish the code coverage achieved by unit tests.

To configure the build to publish test coverage for .NET Core unit tests, the following steps must be performed:

  1. Install the NuGet package, coverlet.msbuild, into the unit test project.
  2. Use the .NET Core task to execute the test and add two parameters to also generate coverage reports, /p:CollectCoverage=true and /p:CoverletOutputFormat=cobertura:

  1. Add the Publish code coverage task:
    1. Set the code coverage tool to cobertura.
    2. Configure $(System.DefaultWorkingDirectory)/**/coverage.cobertura.xml as the summary file:

  1. The build's run details will now contain code coverage reports.

This is all of the configuration needed to generate detailed code coverage reports. The generated reports contain the number of covered and uncovered code blocks and the calculated coverage percentage. These reports are part of the build results page.

Next to unit tests, integration tests can also be run as part of the pipeline and they often come with the challenge of dealing with managing configuration settings.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.150.163