Nelson Baggio
Nelson Baggio

Reputation: 43

Azure DevOps build don't fail when coverage is below target with dotnet test

I have a build pipeline in Azure DevOps for a ASP.NET Core app, and a want use it with a criteria to approve a pull requests.

steps:
      - script: dotnet restore
        displayName: 'Run command: dotnet restore'

      - script: >
                dotnet test 
                /p:CollectCoverage=true 
                /p:CoverletOutputFormat=cobertura 
                /p:Threshold=80 
                /p:ThresholdStat=total 
                /p:Exclude="[*xunit.*]*"
        displayName: 'Run command: dotnet test'

I want when code coverage (using coverlet) don't pass, the build fails. but despite the acceptance criteria do not pass, even a log message is generated, the step runs successfully.

coverlet.msbuild.targets(41,5): error : The total line coverage is below the specified 80 coverlet.msbuild.targets(41,5): error : The total branch coverage is below the specified 80 coverlet.msbuild.targets(41,5): error : The total method coverage is below the specified 80

It's possible force a fail in this case?

Upvotes: 3

Views: 2883

Answers (1)

Shayki Abramczyk
Shayki Abramczyk

Reputation: 41765

Try to run the tests with DotNetCoreCLI@2 task and not with the simple script:

- task: DotNetCoreCLI@2
  displayName: 'dotnet test'
  inputs:
    commands: test
    projects: 'path/to/tests/projects'
    arguments: 'p:CollectCoverage=true
 /p:CoverletOutputFormat=cobertura /p:Threshold=80
 /p:ThresholdStat=total /p:Exclude="[*xunit.*]"'

Upvotes: 9

Related Questions