给定一个 .NET Core CLI 测试任务,特别是
DotNetCoreCLI@2
,
期望发现测试,如何将任务配置为在没有发现测试时失败?
使用较旧的 Visual Studio 测试任务,有用于指定此任务的选项,这就是我的这一期望的基础。
failOnMinTestsNotRun: true
minimumExpectedTests: '1'
据我所知,我们无法设置任务本身来使任务/管道在找不到文件时失败。
解决方法:
您可以使用构建质量检查扩展中的构建质量检查任务。
此任务可以扫描所有设置的任务并检查警告。如果警告数量大于设定的上限,管道将失败。
结果:
据我所知,Azure DevOps 中没有任何开箱即用的东西。
也就是说,有一种说法是您不想检查测试的数量,而是想要检查需要测试的代码。这个论点需要强调。
如果您使用 YAML,您可以在测试任务完成后添加以下内容:
- task: BuildQualityChecks@9
displayName: 'Ensure Code Coverage Quality'
inputs:
# the following ensures that code coverage is at least 76% covered
checkCoverage: true
coverageFailOption: fixed
coverageType: lines # you can update this based on how you run your tests
coverageThreshold: 76
# the following ensures there are no build warnings from prior tasks
checkWarnings: true
warningFailOption: fixed
warningThreshold: 0
要访问 [BuildQualityChecks@9] 任务,您必须从 Azure 市场安装“构建质量检查”:https://marketplace.visualstudio.com/items?itemName=mspremier.BuildQualityChecks