[MTP dotnet test]: Allow specifying project, solution, directory, or test modules as positional argument#53004
Merged
Evangelink merged 4 commits intorelease/10.0.3xxfrom Mar 6, 2026
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Backports behavior to the Microsoft.Testing.Platform (MTP) dotnet test command so a project, solution/solution filter, directory, or test modules can be provided as a positional argument (similar to prior VSTest behavior), while still keeping validation for ambiguous/incorrect usage.
Changes:
- Adds parsing of the first unmatched token as a positional “path/test-modules” input and forwards remaining unmatched tokens to the test application.
- Updates mutual-exclusion/validation logic to work off computed
PathOptions(including the newTestModulesfield). - Expands/adjusts tests to cover positional
.slnfand to ensure helpful validation errors still appear for non-first path-like tokens.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| test/dotnet.Tests/CommandTests/Test/TestCommandValidationTests.cs | Updates validation tests to keep path-like tokens from being the first unmatched token. |
| test/dotnet.Tests/CommandTests/Test/GivenDotnetTestBuildsAndRunsTestsWithDifferentOptions.cs | Adds test coverage for solution filter (.slnf) as the first positional token. |
| src/Cli/dotnet/Commands/Test/MTP/ValidationUtility.cs | Refactors option mutual-exclusion/irrelevant-option validation to use PathOptions.TestModules. |
| src/Cli/dotnet/Commands/Test/MTP/TestModulesFilterHandler.cs | Adjusts handler signature to accept test-modules value from computed build/path options. |
| src/Cli/dotnet/Commands/Test/MTP/TestApplication.cs | Switches forwarded args from UnmatchedTokens to TestApplicationArguments. |
| src/Cli/dotnet/Commands/Test/MTP/Options.cs | Extends PathOptions to include TestModules and renames forwarded-args list in BuildOptions. |
| src/Cli/dotnet/Commands/Test/MTP/MicrosoftTestingPlatformTestCommand.cs | Uses computed build options earlier and routes into test-modules mode based on PathOptions.TestModules. |
| src/Cli/dotnet/Commands/Test/MTP/MSBuildUtility.cs | Implements positional-argument extraction and updates build option construction accordingly. |
fb0a2f0 to
da31109
Compare
…test modules as positional argument (#52449)
566158c to
7605d6f
Compare
Evangelink
requested changes
Mar 6, 2026
Member
Evangelink
left a comment
There was a problem hiding this comment.
Review Summary
This is a manual backport of #52449 to release/10.0.3xx. The adaptation to the branch's command definition API looks correct in most places, but there are a few issues:
High severity
- Directory positional argument is misclassified as
positionalTestModulesinstead ofpositionalProjectOrSolution, which will cause runtime failures when users pass a directory as a positional argument (the test-modules glob matcher won't find anything and will produce a confusing "no test modules found" error). This bug is also present in the original PR onmain. - Missing parentheses in the
||/&&condition — works by accident due to precedence but inconsistent and fragile.
Medium severity
- Dead variable
filterModeEnabledleft behind inMicrosoftTestingPlatformTestCommand.cs. - Missing test coverage for
.csproj,.sln,.slnx, directory, and.dll/.exeas positional arguments, and for the option+positional conflict error.
Low severity
- Extra blank line between methods in
MSBuildUtility.cs.
test/dotnet.Tests/CommandTests/Test/GivenDotnetTestBuildsAndRunsTestsWithDifferentOptions.cs
Show resolved
Hide resolved
Evangelink
approved these changes
Mar 6, 2026
Youssef1313
commented
Mar 6, 2026
test/dotnet.Tests/CommandTests/Test/GivenDotnetTestBuildsAndRunsTestsWithDifferentOptions.cs
Outdated
Show resolved
Hide resolved
This was referenced Mar 6, 2026
Open
This was referenced Mar 12, 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.
Manual backport of #52449 to 10.0.3xx
Closes #52636