![](/img/trans.png)
[英]Azure DevOps 2019 Server failed on executing tests with code coverage
[英]Displaying NUnit tests code coverage on Azure DevOps
我在 Azure DevOps 上設置了一個新管道,用於構建和運行項目的測試。 測試是用 NUnit 編寫的。
在管道中,我使用VSTest@2
任務來運行單元測試,並將codeCoverageEnabled
添加到true
。
最后管道運行,當我在作業的“代碼覆蓋率”選項卡中 go 時,它允許我下載.codecoverage
文件,但它不會在選項卡中顯示其內容。 我的理解是這應該發生。
我怎樣才能解決這個問題?
謝謝
默認情況下,VSTest 任務的代碼覆蓋率為 output 到.codecoverage
文件,Azure DevOps 不知道如何解釋,僅作為可下載文件提供。 您需要使用一些DotNetCoreCLI
任務和Coverlet才能在 azure 管道的代碼覆蓋率選項卡上顯示代碼覆蓋率結果。
因此,如果您使用的是 .NET CORE,那么您有辦法做到這一點。
第 1 步在您的測試項目中添加Coverlet.collector
nuget Package
第 2 步更改您的azure-pipelines.yml
以包含以下代碼覆蓋率:如果您有來自CodeCoverage.runsettings
文件的任何設置,您也可以保留它們
- task: DotNetCoreCLI@2
inputs:
command: 'test'
projects: '**/*.Tests/*.csproj'
arguments: -c $(BuildConfiguration) --collect:"XPlat Code Coverage" -- RunConfiguration.DisableAppDomain=true
testRunTitle: 'Run Test and collect Coverage'
displayName: 'Running tests'
- task: DotNetCoreCLI@2
inputs:
command: custom
custom: tool
arguments: install --tool-path . dotnet-reportgenerator-globaltool
displayName: Install ReportGenerator tool
- script: reportgenerator -reports:$(Agent.TempDirectory)/**/coverage.cobertura.xml -targetdir:$(Build.SourcesDirectory)/coverlet/reports -reporttypes:"Cobertura"
displayName: Create reports
- task: PublishCodeCoverageResults@1
displayName: 'Publish code coverage'
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: $(Build.SourcesDirectory)/coverlet/reports/Cobertura.xml
上述代碼要注意的另一件事是Report Generator 。 根據您使用的 .net 內核的版本,可能需要獲取不同版本的工具。
更多信息也可以在Microsoft Docs上找到
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.