Skip to content

Add coverlet.collector to test project to fix CI coverage gate failure#76

Merged
Chris-Wolfgang merged 11 commits intomainfrom
copilot/add-coverlet-collector-reference
Mar 12, 2026
Merged

Add coverlet.collector to test project to fix CI coverage gate failure#76
Chris-Wolfgang merged 11 commits intomainfrom
copilot/add-coverlet-collector-reference

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 12, 2026

dotnet test --collect:"XPlat Code Coverage" requires coverlet.collector to be referenced directly in the test project to activate the data collector and emit coverage.cobertura.xml. Without it, TestResults/ stays empty, CoverageReport/Summary.txt is never generated, and the Stage 1 coverage gate fails.

Description

Added coverlet.collector v6.0.4 as a PackageReference to Wolfgang.Etl.Abstractions.Tests.Unit.csproj, scoped to the net5.0–net10.0 target frameworks that participate in coverage collection. Consolidated into a single ItemGroup rather than duplicating across per-TFM groups.

<!-- coverlet.collector is required by dotnet test to generate coverage.cobertura.xml when
     using XPlat Code Coverage collection. It must be referenced in the test project for
     net5.0 and greater; .NET Framework and netcoreapp3.1 targets do not participate in
     coverage collection. -->
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'  OR
                      '$(TargetFramework)' == 'net6.0'  OR
                      '$(TargetFramework)' == 'net7.0'  OR
                      '$(TargetFramework)' == 'net8.0'  OR
                      '$(TargetFramework)' == 'net9.0'  OR
                      '$(TargetFramework)' == 'net10.0'">
  <PackageReference Include="coverlet.collector" Version="6.0.4">
    <PrivateAssets>all</PrivateAssets>
    <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
  </PackageReference>
</ItemGroup>

The existing coverlet.runsettings at the repo root was already correctly configured — no changes needed there.

Type of change

  • Bug fix

How Has This Been Tested?

  • Ran dotnet test --framework net8.0 --collect:"XPlat Code Coverage" --settings coverlet.runsettings --results-directory "./TestResults" locally — confirmed TestResults/**/coverage.cobertura.xml is produced (102 passed, 12 skipped).

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Screenshots (if applicable)

N/A

Additional context

coverlet.collector is a dev-only dependency (PrivateAssets>all) and does not affect the shipped library. It is not needed on .NET Framework or netcoreapp3.1 targets because those frameworks are excluded from coverage collection in the CI workflow.

Original prompt

The CI/CD workflow in .github/workflows/pr.yaml fails on the Linux coverage step because no coverage.cobertura.xml files are found in TestResults, resulting in a missing CoverageReport/Summary.txt and a failure exit code. The test project tests/Wolfgang.Etl.Abstractions.Tests.Unit/Wolfgang.Etl.Abstractions.Tests.Unit.csproj does not include a reference to coverlet.collector, which is required for dotnet test --collect:"XPlat Code Coverage" to generate coverage reports with the .NET test SDK.

Solution:

  1. Add coverlet.collector as a PackageReference to all target frameworks (net5.0 and greater) in Wolfgang.Etl.Abstractions.Tests.Unit.csproj.
  2. Ensure coverlet.runsettings is present at the repo root for coverage collection (or correct its path if needed).
  3. (Optional, for diagnostics) Output the workspace directory contents after test runs to aid troubleshooting.

After the fix, verify that coverage.cobertura.xml is found in ./TestResults after tests run and the pipeline passes the coverage gate.

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: Please find a solution for this failing job. Use the logs, job definition, and any referenced files where the failure occurred. Keep your response focused on the solution and include code suggestions when appropriate.

Assistant: The main cause of your failing job is that no test projects were found in the ./tests directory, leading to these problems:

  • No tests are executed, resulting in no coverage files being generated.
  • The workflow is designed to fail if the coverage report (CoverageReport/Summary.txt) is missing or incomplete.

Solution

1. Ensure Test Projects Exist in ./tests

Move or create your .NET test projects (for example, .csproj files with test code) under the ./tests directory, so that the workflow can discover them.

2. Verify Test Discovery in the Workflow Script

Your workflow runs code similar to:

mapfile -d '' -t test_projects < <(find ./tests -type f \( -name "*.csproj" -o -name "*.vbproj" -o -name "*.fsproj" \) -print0)
if [ ${#test_projects[@]} -eq 0 ]; then
  echo "❌ No test projects found in ./tests directory!"
  exit 1
fi

If your tests are not under ./tests, this will always fail. Either:

  • Move test projects under ./tests
  • Or, update the workflow to match their actual location.

3. Commit Example Test Projects

If you don’t have unit tests, add at least a sample test project in ./tests, even if minimal. Example:

  • Create directory: ./tests/Wolfgang.Etl.Abstractions.Tests.Unit/
  • Add a .csproj and a basic test class.

4. Rerun the Workflow

After resolving the test project path, push your change to trigger the workflow again.


Example Directory Structure:

ETL-Abstractions/
  src/
  tests/
    Wolfgang.Etl.Abstractions.Tests.Unit/
      Wolfgang.Etl.Abstractions.Tests.Unit.csproj
      BaseClassTests.cs
  .github/
    workflows/
      pr.yaml

Summary:
Make sure your test projects are in the ./tests directory, or update the workflow paths to wherever the tests are located. This will resolve the "❌ No test projects found" error, allow tests and coverage to run, and generate the required coverage report for your job to succeed.

User: Describe this image

Assistant: The images show the structure of the ETL-Abstractions repository on GitHub.

Image 1 displays the root directory of the repository. The key folders and files visible include:

  • .github (workflows/scripts)
  • benchmarks
  • docfx_project
  • docs
  • examples
  • scripts
  • src/Wolfgang.Etl.Abstractions
  • tests/Wolfgang.Etl.Abstractions.Tests.Unit (highlighted, indicating test code exists under the tests directory)
  • Various configuration files like .editorconfig, .gitattributes, and .gitignore.

Image 2 shows the contents of the tests/Wolfgang.Etl.Abstractions.Tests.Unit directory. Inside, there are:

  • Two subdirectories: BaseClassTests and Models
  • A C# file: ReportTests.cs
  • The project file: Wolfgang.Etl.Abstractions.Tests.Unit.csproj

This folder structure confirms that a test project and test files do exist under ./tests/Wolfgang.Etl.Abstractions.Tests.Unit as expected.

User: so whats the issue

Assistant: Based on the images and the job log:

  • Your repository does in fact have a test project located at tests/Wolfgang.Etl.Abstractions.Tests.Unit/Wolfgang.Etl.Abstractions.Tests.Unit.csproj.
  • The workflow log error says: ❌ No test projects found in ./tests directory!

Possible reasons for this apparent mismatch:

1. Shell Script Error: Array Expansion

If your workflow uses this block:

mapfile -d '' -t test_projects < <(find ./tests -type f \( -name "*.csproj" -o -name "*.vbproj" -o -name "*.fsproj" \) -print0)
if [ ${#test_projects[@]} -eq 0 ]; then
  echo "❌ No test projects found in ./tests directory!"
  exit 1
fi

But: If there’s a problem with the shell or the environment (e.g., runni...

This pull request was created from Copilot chat.


💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.

Co-authored-by: Chris-Wolfgang <210299580+Chris-Wolfgang@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix CI/CD coverage report generation in tests Add coverlet.collector to test project to fix CI coverage gate failure Mar 12, 2026
@Chris-Wolfgang Chris-Wolfgang marked this pull request as ready for review March 12, 2026 17:21
Copilot AI review requested due to automatic review settings March 12, 2026 17:21
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a CI coverage gate failure by adding the coverlet.collector NuGet package reference to the test project, which is required for dotnet test --collect:"XPlat Code Coverage" to generate coverage.cobertura.xml files.

Changes:

  • Added coverlet.collector v6.0.4 as a dev-only PackageReference scoped to net5.0–net10.0 target frameworks in the unit test project.

You can also share your feedback on Copilot code review. Take the survey.

Copilot AI and others added 9 commits March 12, 2026 17:37
Co-authored-by: Chris-Wolfgang <210299580+Chris-Wolfgang@users.noreply.github.com>
Co-authored-by: Chris-Wolfgang <210299580+Chris-Wolfgang@users.noreply.github.com>
Co-authored-by: Chris-Wolfgang <210299580+Chris-Wolfgang@users.noreply.github.com>
…Stage 3 only

Co-authored-by: Chris-Wolfgang <210299580+Chris-Wolfgang@users.noreply.github.com>
…-workflow

Fix macOS grep -P incompatibility in Stage 3 coverage threshold enforcement (pr.yaml)
@Chris-Wolfgang Chris-Wolfgang merged commit 44a9e13 into main Mar 12, 2026
13 of 15 checks passed
@Chris-Wolfgang Chris-Wolfgang deleted the copilot/add-coverlet-collector-reference branch March 12, 2026 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants