如何将 xUnit 覆盖率报告上传到 Codecov?

问题描述

我有一个 .Net 5 解决方案,其中包含多个 xUnit 测试项目,这是一个托管在 Github 上的公共存储库。我想生成代码覆盖率报告并将其显示在 Codecov 上。

首先我跑

dotnet add package coverlet.msbuild

对于每个测试项目。我知道我可以导航到 .sln 目录并通过

生成新报告

dotnet test /p:CollectCoverage=true

我授权了 Codecov,所以它知道这个项目。我认为只有 maindev 分支是相关的,所以我从这个工作流程开始

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

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)