本文介绍了NET Core 3.1的Azure DevOps代码覆盖率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在为ASP.NET Core 3.1应用程序设置Azure DevOps管道,并且我具有以下YAML定义测试段),用于构建,测试和代码覆盖.
I am setting up an Azure DevOps pipeline for an ASP.NET Core 3.1 Application and I have the following YAML definition test segment) for building, testing and code coverage.
- task: DotNetCoreCLI@2 displayName: "dotnet global test tool install" inputs: command: 'custom' custom: 'tool' arguments: 'install --global dotnet-reportgenerator-globaltool' - task: DotNetCoreCLI@2 displayName: "dotnet test" inputs: command: 'test' projects: '**/*[Tt]ests' arguments: '--no-build --configuration $(buildConfiguration) /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput=$(System.DefaultWorkingDirectory)/TestResults/Coverage' testRunTitle: 'Unit Test' workingDirectory: '$(System.DefaultWorkingDirectory)' - script: reportgenerator -reports:$(System.DefaultWorkingDirectory)/**/cobertura/coverage.xml -targetdir:$(System.DefaultWorkingDirectory)/CodeCoverage -reporttypes:HtmlInLine_AzurePipelines displayName: "create code coverage report" - task: PublishCodeCoverageResults@1 displayName: "publish test coverage result" inputs: codeCoverageTool: 'Cobertura' summaryFileLocation: '$(System.DefaultWorkingDirectory)/**/cobertura/coverage.xml'在Azure DevOps中运行时,出现以下错误
Upon running in Azure DevOps, I get the following error
我可能做错了什么?项目来源: GitHub
What could I be doing wrong? Project Source: GitHub
推荐答案最后在Microsoft MVP的帮助下使其工作.共享有效的测试段中的代码.
Finally got it working with the help of a Microsoft MVP. Sharing the code from the test segment that worked.
- task: DotNetCoreCLI@2 displayName: "dotnet global test tool install" inputs: command: 'custom' custom: 'tool' arguments: 'install --global dotnet-reportgenerator-globaltool' - script: dotnet test WebApp.Web.Tests/WebApp.Web.Tests.csproj --logger "trx;LogFileName=testresults.trx" /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput=$(Build.SourcesDirectory)/TestResults/Coverage/ displayName: 'dotnet test' - script: reportgenerator "-reports:$(Build.SourcesDirectory)/TestResults/Coverage/coverage.cobertura.xml" "-targetDir:$(Build.SourcesDirectory)/TestResults/Coverage/Reports" -tag:$(Build.BuildNumber) -reportTypes:htmlInline workingDirectory: $(Build.SourcesDirectory)/WebApp.Web.Tests displayName: 'dotnet reportgenerator' - task: PublishTestResults@2 inputs: testRunner: VSTest testResultsFiles: '**/*.trx' failTaskOnFailedTests: true - task: PublishCodeCoverageResults@1 inputs: codeCoverageTool: 'cobertura' summaryFileLocation: $(Build.SourcesDirectory)/TestResults/Coverage/**/coverage.cobertura.xml reportDirectory: $(Build.SourcesDirectory)/TestResults/Coverage/Reports failIfCoverageEmpty: false可以在此处找到资源.
更多推荐
NET Core 3.1的Azure DevOps代码覆盖率
发布评论