Repository navigation
Add dotnet test --results-directory-layout to stop test reports overwriting each other - #55475
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new dotnet test option for Microsoft.Testing.Platform (MTP) that controls how the results directory is laid out across multiple test modules, preventing report files with the same relative name from overwriting each other when running solutions.
Changes:
- Introduces
--results-directory-layout <flat|per-module>(defaultflat) and wires it through parsing, help text, and localization resources. - Adds an SDK-side
TestResultsDirectoryResolverand refactors the MTP handler pipeline to enumerate all modules up front so per-module directories can be computed deterministically (including name-collision disambiguation). - Adds unit + end-to-end regression tests plus new test assets to validate overwrites in
flatand separation inper-module, including duplicate project-name scenarios.
Show a summary per file
| File | Description |
|---|---|
| test/TestAssets/TestProjects/MultiTestProjectSolutionWithSharedReportName/TestProjectA/TestProjectA.csproj | New MTP test asset project A to reproduce shared relative report name behavior. |
| test/TestAssets/TestProjects/MultiTestProjectSolutionWithSharedReportName/TestProjectA/Program.cs | Writes a relative report.txt into MTP’s results directory to validate overwrite/separation. |
| test/TestAssets/TestProjects/MultiTestProjectSolutionWithSharedReportName/TestProjectB/TestProjectB.csproj | New MTP test asset project B paired with project A. |
| test/TestAssets/TestProjects/MultiTestProjectSolutionWithSharedReportName/TestProjectB/Program.cs | Writes a relative report.txt with different content to detect overwrites. |
| test/TestAssets/TestProjects/MultiTestProjectSolutionWithSharedReportName/MultiTestProjectSolutionWithSharedReportName.sln | New solution containing both test assets for the overwrite regression. |
| test/TestAssets/TestProjects/MultiTestProjectSolutionWithSharedReportName/global.json | Configures the test runner as Microsoft.Testing.Platform for the asset. |
| test/TestAssets/TestProjects/MultiTestProjectSolutionWithDuplicateProjectNames/src/Tests/Tests.csproj | New asset for duplicate project-name disambiguation case (src). |
| test/TestAssets/TestProjects/MultiTestProjectSolutionWithDuplicateProjectNames/src/Tests/Program.cs | Produces a report to verify hashed disambiguation preserves both outputs. |
| test/TestAssets/TestProjects/MultiTestProjectSolutionWithDuplicateProjectNames/samples/Tests/Tests.csproj | New asset for duplicate project-name disambiguation case (samples). |
| test/TestAssets/TestProjects/MultiTestProjectSolutionWithDuplicateProjectNames/samples/Tests/Program.cs | Produces a report to verify both projects with same name are kept distinct. |
| test/TestAssets/TestProjects/MultiTestProjectSolutionWithDuplicateProjectNames/MultiTestProjectSolutionWithDuplicateProjectNames.slnx | Solution file used for duplicate-name disambiguation testing. |
| test/TestAssets/TestProjects/MultiTestProjectSolutionWithDuplicateProjectNames/global.json | Configures MTP runner for the duplicate-name solution asset. |
| test/dotnet.Tests/CommandTests/Test/TestResultsDirectoryResolverTests.cs | New unit tests covering resolver behavior (flat/per-module, pivoting, sanitization, hashing, stability). |
| test/dotnet.Tests/CommandTests/Test/TestCommandParserTests.cs | Parser tests for new --results-directory-layout option and invalid value rejection. |
| test/dotnet.Tests/CommandTests/Test/snapshots/MTPHelpSnapshotTests.VerifyMTPHelpOutput.verified.txt | Updates MTP help snapshot to include new option documentation. |
| test/dotnet.Tests/CommandTests/Test/GivenDotnetTestBuildsAndRunsTests.cs | End-to-end tests for per-module directory creation and overwrite regression/disambiguation scenarios. |
| src/Cli/Microsoft.DotNet.Cli.Definitions/Commands/Test/TestCommandDefinition.MicrosoftTestingPlatform.cs | Adds the new CLI option and integrates it into the MTP command options list. |
| src/Cli/Microsoft.DotNet.Cli.Definitions/CommandDefinitionStrings.resx | Adds localized string resources for the new option help text and metavar name. |
| src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.cs.xlf | Adds XLF entries for the new option strings. |
| src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.de.xlf | Adds XLF entries for the new option strings. |
| src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.es.xlf | Adds XLF entries for the new option strings. |
| src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.fr.xlf | Adds XLF entries for the new option strings. |
| src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.it.xlf | Adds XLF entries for the new option strings. |
| src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.ja.xlf | Adds XLF entries for the new option strings. |
| src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.ko.xlf | Adds XLF entries for the new option strings. |
| src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.pl.xlf | Adds XLF entries for the new option strings. |
| src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.pt-BR.xlf | Adds XLF entries for the new option strings. |
| src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.ru.xlf | Adds XLF entries for the new option strings. |
| src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.tr.xlf | Adds XLF entries for the new option strings. |
| src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.zh-Hans.xlf | Adds XLF entries for the new option strings. |
| src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.zh-Hant.xlf | Adds XLF entries for the new option strings. |
| src/Cli/dotnet/Commands/Test/MTP/Options.cs | Introduces ResultsDirectoryLayout enum and threads it into PathOptions. |
| src/Cli/dotnet/Commands/Test/MTP/MSBuildUtility.cs | Parses --results-directory-layout and stores the chosen layout in PathOptions. |
| src/Cli/dotnet/Commands/Test/MTP/TestResultsDirectoryResolver.cs | New resolver implementing the flat vs per-module layout, including collision hashing and sanitization. |
| src/Cli/dotnet/Commands/Test/MTP/ITestHandler.cs | Extends handler contract to enumerate all modules after initialization. |
| src/Cli/dotnet/Commands/Test/MTP/TestModulesFilterHandler.cs | Refactors to build module list in Initialize() and expose it via EnumerateTestModules(). |
| src/Cli/dotnet/Commands/Test/MTP/MSBuildHandler.cs | Implements EnumerateTestModules() for MSBuild-discovered modules. |
| src/Cli/dotnet/Commands/Test/MTP/MicrosoftTestingPlatformTestCommand.cs | Creates a TestResultsDirectoryResolver and passes it into the execution pipeline. |
| src/Cli/dotnet/Commands/Test/MTP/TestApplicationActionQueue.cs | Plumbs resolver through the parallel action queue to per-module test application execution. |
| src/Cli/dotnet/Commands/Test/MTP/TestApplication.cs | Uses resolver output to decide whether/how to append --results-directory per test module. |
Copilot's findings
- Files reviewed: 40/40 changed files
- Comments generated: 0
Evangelink
enabled auto-merge
July 27, 2026 11:38
Evangelink
force-pushed
the
dev/amauryleve/test-results-layout
branch
from
July 27, 2026 11:54
2a806aa to
b09a9c4
Compare
YuliiaKovalova
approved these changes
Jul 27, 2026
When 'dotnet test' runs a solution, every test application resolves the same shared TestResults directory, so reports configured with a relative file name (--coverage-output, --report-trx-filename, ...) overwrite each other and coverage data is silently lost (microsoft/codecoverage#226). Add an SDK-side layout policy for the Microsoft.Testing.Platform path: dotnet test --results-directory-layout <flat|per-module> 'flat' is the default and keeps today's behavior. 'per-module' gives every test application its own directory, modeled on the artifacts output layout: <results-directory>/<project>/<target-framework>_<runtime> Microsoft.Testing.Platform gains no new option; the SDK simply passes an explicit --results-directory per child process, so the whole module set is resolved up front. That also lets the layout append an identity hash to the project folder only when two distinct projects in the run share a name. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 0cb64c89-128b-4f8f-88cc-2741ffac3767
Evangelink
force-pushed
the
dev/amauryleve/test-results-layout
branch
from
July 27, 2026 16:17
b09a9c4 to
d73fa64
Compare
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 00868f6a-f41f-422e-aaf7-0cc9f56142a1
baronfel
approved these changes
Aug 3, 2026
baronfel
left a comment
Member
There was a problem hiding this comment.
containers tests changes LGTM
azat-msft
approved these changes
Aug 4, 2026
Member
Author
mthalman
approved these changes
Aug 4, 2026
YuliiaKovalova
approved these changes
Aug 4, 2026
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: cae287b8-f62a-4246-94cd-bb162e1273a6
Member
Author
|
@lbussell it seems that I need your approval. |
lbussell
approved these changes
Aug 5, 2026
This was referenced Nov 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When
dotnet testruns a solution, every test application resolves the same sharedTestResultsdirectory. Reports configured with a relative file name therefore overwrite each other and results are silently lost:Reported in microsoft/codecoverage#226; the same happens with
--report-trx-filenameand xUnit's report options. This became visible once MTP started honoringDOTNET_CLI_TEST_COMMAND_WORKING_DIRECTORY, whichdotnet testsets to the solution root (#52398 / #52570).Change
Adds an SDK-side layout policy for the Microsoft.Testing.Platform path:
flat— the default, byte-for-byte today's behavior. When the user passes no--results-directory, no argument is forwarded to the child process, exactly as before.per-module— every test application gets its own directory, modeled on the artifacts output layout:Real output for a two-project solution:
Multi-targeting nests naturally (
MyTests/net9.0_x64,MyTests/net10.0_x64) instead of producing sibling folders with concatenated names.MTP gains no new option — the SDK just passes an explicit
--results-directoryper child process. "Per-module" has no meaning for a single test application, so the policy belongs to the aggregating layer that knows the whole module set.Name collisions
Project names aren't unique within a run, so the whole module set is resolved up front and an identity hash is appended only when two distinct projects share a name:
The hash is anchored to the directory common to all modules, so it doesn't change with the directory
dotnet testwas invoked from. Knowing the module set before anything runs requiredITestHandler.EnumerateTestModules(), andTestModulesFilterHandlernow builds its module list inInitialize()rather than as items are dequeued.Tests
TestResultsDirectoryResolverTests— flat passthrough, nesting, multi-TFM, disambiguation, CWD-independence, cross-run stability, RID pivots, dotted-name sanitization,--test-modulesfallback.flat/per-moduleand rejection of invalid values; help snapshot updated.GetTestResultDirectory():flatyields 1 surviving report,per-moduleyields 2 with distinct contents.Tests.37 targeted tests pass locally, including the existing
--test-modules, globbing, and MSBuild handler suites that cover the refactor.Notes for reviewers
flatto avoid changing output paths in a patch. Longer term I thinkper-moduleis the safer default, since silent data loss on a common flag is a bad failure mode — happy to follow up separately.--diagnostic-output-directoryis still forwarded unchanged and is not scoped per module.