Search code examples
.net-coreazure-pipelinesnunit

Dotnet test with NUnit combine results from 2 runs with different filters


I would like to get a combined test coverage report when running dotnet test with different filters.

In my NUnit tests I added categories Unit and Integration.

This is how I run the tests for each:

dotnet test --filter Category=Unit
dotnet test --filter Category=Integration

I do this so that in my pipeline I can run these as separate tasks. Only if the Unit tests pass do I move onto the next task and run the Integration tests.

I would like to combine the coverage reports for each into one coverage report for all tests (Unit and Integration). Is this possible?


Solution

  • I would like to combine the coverage reports for each into one coverage report for all tests (Unit and Integration). Is this possible?

    The answer is yes. You can use the Report Generator task from ReportGenerator extension.

    This task supports combining the code coverage reports into one coverage report. Then it will create a new code coverage report.

    Here is an example:

    - task: reportgenerator@4
      inputs:
        reports: '$(Build.SourcesDirectory)/**/*.cobertura.xml'
        targetdir: '$(Build.SourcesDirectory)/CoverageResults'
    
    - task: PublishCodeCoverageResults@1
      displayName: 'Publish code coverage'
      inputs:
        codeCoverageTool: Cobertura
        summaryFileLocation: '$(Build.SourcesDirectory)/CoverageResults/Cobertura.xml'