在 Azure DevOps 管道内,我使用下一个 YML 代码设置了代码覆盖率:
- stage: Test_application
jobs:
- job:
steps:
- task: DotNetCoreCLI@2
displayName: 'DotNet Test'
inputs:
command: 'test'
arguments: '--configuration Release --collect "Code coverage"'
projects: '**/MyLibrary.UnitTest.*.csproj'
但是当我查看结果时,它似乎还包括包
diffengine.dll
,moq.dll
和shouldly.dll
。是什么让代码覆盖率达到 9.82%。
但是这些包是从 NuGet 下载的,必须从结果中排除。结果一定是(我认为) 31.61%。只取
MyLibrary.One.dll
、MyLibrary.Two.dll
、MyLibrary.Tree.dll
和MyLibrary.Four.dll
。
我怎样才能只过滤这些
dll
?
您可以在存储库中使用像这样的运行设置文件:
<?xml version="1.0" encoding="utf-8" ?>
<RunSettings>
<DataCollectionRunSettings>
<DataCollectors>
<DataCollector friendlyName="Code Coverage">
<Configuration>
<CodeCoverage>
<ModulePaths>
<Include>
<ModulePath>YOUR_DLL_NAME_HERE.dll</ModulePath>
</Include>
</ModulePaths>
</CodeCoverage>
</Configuration>
</DataCollector>
</DataCollectors>
</DataCollectionRunSettings>
</RunSettings>
然后在管道中使用它
- stage: Test_application
jobs:
- job:
steps:
- task: DotNetCoreCLI@2
displayName: 'DotNet Test'
inputs:
command: 'test'
arguments: '--configuration Release --collect "Code coverage" --settings:$(Build.SourcesDirectory)\codecoverage.runsettings'
projects: '**/MyLibrary.UnitTest.*.csproj'