我想根据本教程为我的C#项目生成一个覆盖报告。
https://learn.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检查目录时,我可以看到没有匹配的文件(尽管它们应该存在)。
我希望每个测试项目都有一个coverage.cobertura.xml文件。
...\myRepo\xUnitTestProject1\TestResults\380e65f7-48d5-468f-9cbc-550c8e0aeda8\coverage.cobertura.xml...\myRepo\xUnitTestProject2\TestResults\c96c55f7-40d3-483e-a136-573615e3a9c3\coverage.cobertura.xml当前解决方案:
看来我得再运行一次了。所以我换了这条线
dotnet test --no-build --output build --collect:"XPlat Code Coverage";
使用
dotnet test --collect:"XPlat Code Coverage";
现在它工作得很好,但是额外的构建似乎是多余的,因为我已经创建了一个构建工件..。
那么,您有什么想法,如何改进配置,使我不必再构建第二次?
发布于 2021-08-07 14:05:03
看来您可以将这两个步骤结合起来,因为dotnet test也将触发构建。您可能已经构建了与测试相同阶段报告的问题,但两者都有相似的响应。
image: mcr.microsoft.com/dotnet/sdk:5.0
stages:
- unit-tests
unit-tests:
stage: unit-tests
script:
- |-
dotnet test --output build --collect:"XPlat Code Coverage";
dotnet tool install -g dotnet-reportgenerator-globaltool;
reportgenerator -reports:'../coverage.cobertura.xml' -targetdir:'CoverageReports' -reporttypes:'Cobertura';
artifacts:
paths:
- build
reports:
cobertura: CoverageReports/Cobertura.xml或者:封面收集器依赖于CoreCompile。但是,Global没有(因为它不是msbuild任务)。
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 coverlet.console;
dotnet tool install -g dotnet-reportgenerator-globaltool;
coverlet /path/to/test-assembly.dll --target "dotnet" --targetargs "test /path/to/test-project --no-build";
reportgenerator -reports:'../coverage.cobertura.xml' -targetdir:'CoverageReports' -reporttypes:'Cobertura';
artifacts:
reports:
cobertura: CoverageReports/Cobertura.xml
dependencies:
- buildCoverlet的全局工具也支持一个--format cobertura选项,这可能有助于进一步简化这一点。
https://stackoverflow.com/questions/68591472
复制相似问题