我有一个包含多个xUnit测试项目的Github5解决方案,这是一个托管在Github上的公共存储库。我想生成代码覆盖率报告,并在Codecov上显示它们。
首先我跑
dotnet add package coverlet.msbuild
对于每个测试项目。我知道我可以导航到.sln目录并通过
dotnet test /p:CollectCoverage=true
我授权了Codecov,所以它知道这个项目。我认为只有main和dev分支是相关的,所以我从这个工作流开始
name: Generate coverage report on push
on:
push:
branches:
- 'main'
- 'dev'
jobs:
generate-coverage-report-on-push:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./DirectoryWithSlnFile
steps:
- uses: actions/checkout@v2
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build project
run: dotnet build --no-restore
- name: Generate coverage report
run: dotnet test --no-build --verbosity normal /p:CollectCoverage=true现在需要做什么才能将报告从所有测试项目上传到Codecov?例如。
- name: Upload coverage report
run: upload to Codecov with CODECOV_TOKEN if pushed on main or dev发布于 2021-09-18 20:18:04
我只是在遇到同样的问题时偶然发现了这一点。这就是我让它工作的方式。
首先,您已经完成的步骤,但只是为了完整性。将coverlet添加到测试项目:
dotnet add package coverlet.msbuild然后,在GitHub操作工作流文件中,添加以下步骤:
- name: Test
run: dotnet test --no-build --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=opencover
- name: Codecov
uses: codecov/codecov-action@v2
with:
file: coverage.opencover.xml
directory: FUI.Testshttps://stackoverflow.com/questions/67911653
复制相似问题