Skip to content

--coverage-output flag silently omits/deletes output files when solution has multiple test projects #56930

Closed

Description

@computaserik

Describe the bug

If dotnet test --coverage is run with the flag --coverage-output in a solution with multiple test projects, there will be a report from only one of the test projects

Steps to reproduce

  1. Create a solution with two test projects using MTP
  2. Run dotnet test --coverage --coverage-output-format cobertura --coverage-output my-output-file.xml
  3. Inspect the output

Minimal demo: https://github.com/computaserik/CoverageOutputDemo/tree/main

Expected behavior

dotnet test should fail, or at least issue a clear warning that output will be missing.

Actual behavior

The test reports from all but one of the projects are silently omitted/deleted.

Is this a regression?

No response

Are there any workarounds?

Remove the --coverage-output option.

dotnet --info output

IDE version

No response

Other details

No response

Activity

  1. added
    untriaged
    on Nov 4, 2026
  2. computaserik commented on Nov 4, 2026

    @computaserik
    Author

    The only hint I found of this behaviour is buried in xUnit documentation: https://xunit.net/docs/getting-started/v3/code-coverage-with-mtp#enabling-code-coverage

  3. locked and limited conversation to collaborators on Nov 4, 2026
  4. unlocked this conversation on Nov 4, 2026
  5. added
    needs team triage
    and removed
    untriaged
    on Nov 4, 2026
  6. github-actions commented on Nov 4, 2026

    @github-actions
    Contributor

    🎯 Agentic Issue Triage

    Triage Assessment:

    • 🏷️ Labels: Area-dotnet test Bug needs team triage Requires a full team discussion
    • 💻 Assignment: none | @dotnet/dotnet-testing
    • 🟨 Confidence: medium - Clearly a dotnet test MTP issue, but the owning team has no expandable members for assignment.

    Similar issues: #56796 (potentially related)

    ➡️ Summary: With --coverage-output and multiple MTP test projects, coverage output from all but one project is silently overwritten. Consider failing or warning when the output path is shared across projects.

    Generated by 🏷️ Issue Triage for #56930 · copilot · auto · 20.1 AIC · ⌖ 0.68 AIC · ⊞ 14.6K · ◷

  7. self-assigned this
    on Nov 5, 2026
  8. removed
    needs team triage
    on Nov 5, 2026
  9. added theissue type on Nov 5, 2026
  10. Evangelink commented on Nov 5, 2026

    @Evangelink
    Member

    Thanks for the minimal reproduction. I confirmed the behavior with .NET SDK 10.0.403 and 11.0.100-rc.3, using Microsoft.Testing.Extensions.CodeCoverage 18.12.0: both test projects pass, but only one project's coverage survives when they use the same explicit output filename.

    Why the behavior changed

    This is a consequence of fixing an earlier bug in how dotnet test and Microsoft.Testing.Platform resolved working and results directories.

    Previously, each test application resolved its default TestResults directory relative to its own output directory. That meant test applications belonging to the same dotnet test invocation did not share the common results-directory root, and relative paths could resolve differently between applications.

    The fixes in #52570 and microsoft/testfx#7265 made the SDK communicate the original invocation directory and made MTP honor it. Results now consistently go into the shared TestResults directory beneath the directory where dotnet test was invoked, unless configured otherwise.

    Unfortunately, that exposed a collision for explicit filenames: a name that previously landed in separate directories now points to the same file for every test application. --coverage-output my-output-file.xml is forwarded to each application; it does not request a single combined solution-level report. Each application writes its own report, overwriting the previous contents. Serializing execution does not prevent this.

    How to preserve all coverage reports

    If you do not need a fixed filename, omit --coverage-output:

    dotnet test --coverage --coverage-output-format cobertura

    The coverage extension generates unique GUID-based filenames, so each application's report is preserved. With the SDK 11 version tested, those distinct reports are also automatically merged into a combined coverage report.

    If you need to keep a fixed filename, use the per-module results layout:

    dotnet test --coverage --coverage-output-format cobertura --coverage-output my-output-file.xml --results-directory-layout per-module

    This option was added in #55475 and backported to the .NET SDK 10.0.4xx branch in #55629, including SDK 10.0.403. For your example, it separates the reports into paths such as:

    TestResults\TestProject1\net10.0_x64\my-output-file.xml
    TestResults\TestProject2\net10.0_x64\my-output-file.xml
    

    This applies to a relative filename; explicitly directing every application to the same absolute coverage-output path would still collide.

    The default layout remains flat for compatibility, so the shared-directory fix and the per-module option do not themselves add a warning for your original command. You are right that reporting success without warning about the lost coverage is easy to miss. The explanation above accounts for the behavior change, but the request for a clear warning or failure remains a separate concern.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions