C# Coverage always 0%

Description

I have a mono-repo with a c# backend. I use Coverlet to generate a report. I’ve tried the following formats; json, lcov, opencover, cobertura. All result in 0% coverage when sent to Codecov. It does however show the graph of all files.

Repository

Commit SHAs

a53cebf39b43d60368042d8a2a99936661925bd9

Codecov YAML

codecov:

  require_ci_to_pass: yes

  branch: dev

coverage:

  precision: 2

  round: down

  range: "70...100"

parsers:

  gcov:

    branch_detection:

      conditional: yes

      loop: yes

      method: no

      macro: no

comment:

  layout: "reach,diff,flags,tree"

  behavior: default

  require_changes: no

Additional Information

He is the GitHub action I use to generate and send the report to Codecov.

name: API (.NET Core)

on:
  push:
    branches: [master, dev]
  pull_request:
    branches: [master, dev]

jobs:
  build:
    runs-on: ubuntu-latest
    env:
      working-directory: ./backend
      codeCov-token: ${{ secrets.CodeCov }}

    steps:
      - uses: actions/checkout@v2
      - name: Setup .NET Core
        uses: actions/setup-dotnet@v1
        with:
          dotnet-version: 3.1.101
      - name: Install dependencies
        run: dotnet restore
        working-directory: ${{env.working-directory}}
      - name: Install coverlet for code coverage
        run: dotnet tool install -g coverlet.console
        working-directory: ${{env.working-directory}}
      - name: Build
        run: dotnet build --configuration Release --no-restore
        working-directory: ${{env.working-directory}}
      - name: Test
        run: dotnet test --no-restore --verbosity normal
        working-directory: ${{env.working-directory}}
      - name: Generate code coverage
        run: coverlet ./tests/unit/api/bin/Release/netcoreapp3.1/Pims.Api.Test.dll --target "dotnet" --targetargs "test ./ --no-build" -o "./tests/TestResults/api-coverage.json" --exclude "[*.Test]*" --exclude "[*]*Model" --exclude-by-attribute "CompilerGenerated" -f json
        working-directory: ${{env.working-directory}}
      - name: Merge code coverage
        run: coverlet ./tests/unit/dal/bin/Release/netcoreapp3.1/Pims.Dal.Test.dll --target "dotnet" --targetargs "test ./ --no-build" -o "./tests/TestResults/" --exclude "[*.Test]*" --exclude "[*]*Model" --exclude-by-attribute "CompilerGenerated" --merge-with "./tests/TestResults/api-coverage.json" -f lcov
        working-directory: ${{env.working-directory}}

      - name: Codecov
        uses: codecov/codecov-action@v1.0.7
        with:
          # User defined upload name. Visible in Codecov UI
          name: PIMS
          # Repository upload token - get it from codecov.io. Required only for private repositories
          token: ${{env.codeCov-token}}
          # Path to coverage file to upload
          file: ${{env.working-directory}}/tests/TestResults/coverage.info
          # Flag upload to group coverage metrics (e.g. unittests | integration | ui,chrome)
          flags: unittests
          # Environment variables to tag the upload with (e.g. PYTHON | OS,PYTHON)
          env_vars: C#
          # Specify whether or not CI build should fail if Codecov runs into an error during upload
          fail_ci_if_error: true

Hi @Fosol, I’m not too sure what’s happening here. I currently see coverage for files on your repository page https://codecov.io/gh/Fosol/PIMS.

I can see coverage for that particular commit being processed, but I don’t actually see the commit. Did you rebase or merge over it?

I ended up rebasing and attempting a number of other attempts to resolve. In the end it would appear we needed to use a different tool to generate the reports.

We were using Coverlet to generate our files. Locally we could see they had the relevant information, but uploading them to Codecov just didn’t work.

We are now going to try using the built in report generation with dotnet.

dotnet test --collect:"XPlat Code Coverage" --settings coverlet.runsettings --no-restore

With some configuration we believe this will work. Find out soon, as we’ll be merging into our repo and testing.

Sounds good, if you happen to have a copy of a coverlet report, I’d love to get that to my team to see if it’s supportable in the future.