Daniele Francioni
Daniele Francioni

Reputation: 45

Code Coverage for untested projects in .net core and global threshold

I've set up a Azure DevOps CI pipeline to collect code coverage acquired by using coverlet. I've noticed that, if a project is somehow tested by a project, the report will include info regarding untested classes/code but if, for example, a developer adds a new project without the corresponding test project, the code does not show up in the final report. Moreover, it seems that thresholds can be specified only per test-project (for example, I can have a project that is tested by two different tests projects: both contributes to the code coverage statistic for the original projects). I'm using the "PublishCodeCoverageResults" pipeline task to publish the code coverage results. Is there a way to let the CI build fail if the overall code coverage does not reach a specific threshold?

Upvotes: 1

Views: 548

Answers (1)

starian chen-MSFT
starian chen-MSFT

Reputation: 33708

The code coverage result is based on the test project(s), so, the code coverage result should not includes the projects without corresponding test project.

For overall code coverage threshold, you can use this argument:

--configuration $(BuildConfiguration) /p:CollectCoverage=true /p:threshold=75 /p:thresholdType=line /p:thresholdStat=total /p:CoverletOutputFormat=cobertura

On the other hand, there is a new feature regards Code coverage metrics in pull request: Code coverage metrics and branch policy for pull requests

Upvotes: 1

Related Questions