在GitlabCI管道内运行时,dotnet-reportgenerator无法找到任何coverage.cobertura.xml
c#
我想根据本教程为我的 C# 项目生成单个覆盖率报告
https://docs.microsoft.com/en-us/dotnet/core/testing/unit-testing-code-coverage
使用以下配置启动 Gitlab CI 管道时
image: mcr.microsoft.com/dotnet/sdk:5.0
stages:
- build
- unit-tests
build:
stage: build
script:
- dotnet build --output build
artifacts:
paths:
- build
unit-tests:
stage: unit-tests
script:
- |-
dotnet test --no-build --output build --collect:"XPlat Code Coverage";
dotnet tool install -g dotnet-reportgenerator-globaltool;
reportgenerator -reports:'**/coverage.cobertura.xml' -targetdir:'CoverageReports' -reporttypes:'Cobertura';
artifacts:
reports:
cobertura: CoverageReports/Cobertura.xml
dependencies:
- build
我收到以下错误
报告文件模式“**/coverage.cobertura.xml”无效。没有找到匹配的文件。
ls在运行 reportgenerator 命令之前使用检查目录时,我可以看到没有匹配的文件(尽管它们应该存在)。
我希望每个测试项目有一个coverage.cobertura.xml 文件,例如
...myRepoxUnitTestProject1TestResults380e65f7-48d5-468f-9cbc-550c8e0aeda8coverage.cobertura.xml...myRepoxUnitTestProject2TestResultsc96c55f7-40d3-483e-a136-573615e3a9c3coverage.cobertura.xml
我目前的解决方案:
看来我必须再次运行构建。所以我替换了这条线
dotnet test --no-build --output build --collect:"XPlat Code Coverage";
和
dotnet test --collect:"XPlat Code Coverage";
现在它工作正常,但额外的构建似乎是多余的,因为我已经创建了一个构建工件......
那么你有什么想法如何改进配置,这样我就不必第二次构建了吗?
THE END
二维码