Skip to content

Allow dotnet test --list-tests json for Microsoft.Testing.Platform#54490

Draft
Evangelink wants to merge 1 commit into
mainfrom
dev/amauryleve/list-tests-json
Draft

Allow dotnet test --list-tests json for Microsoft.Testing.Platform#54490
Evangelink wants to merge 1 commit into
mainfrom
dev/amauryleve/list-tests-json

Conversation

@Evangelink
Copy link
Copy Markdown
Member

Fixes #49754

The MTP side added support for --list-tests json in microsoft/testfx#8280. This PR plumbs the optional text/json value through the SDK CLI so users can do:

dotnet test --list-tests json
dotnet test --list-tests text
dotnet test --list-tests        # (unchanged: no value = text behavior)

Changes

  • TestCommandDefinition.MicrosoftTestingPlatform.ListTestsOption: arity ZeroZeroOrOne, restrict accepted values to text/json via AcceptOnlyFromAmong, dedicated HelpName and a new resource string CmdMTPListTestsDescription.
  • TestOptions: new ListTestsArgument field.
  • MicrosoftTestingPlatformTestCommand: read the option value and pass it through.
  • TestApplication.GetArguments: forward the value to the test host (escaped) when present; absent value still emits a bare --list-tests token (no behavioral change for users today).
  • Tests:
    • New theory DiscoverTestProjectForwardsListTestsArgument (Debug/Release × text/json) asserts the value is forwarded as a separate arg.
    • New theory DiscoverTestProjectRejectsInvalidListTestsArgument asserts foo/JSON/TEXT are rejected (validator is case-sensitive, matching MTP's lowercase keys).
    • Existing DiscoverTestProjectWithCustomRunArgumentsAndTestEscaping continues to assert the bare --list-tests token forwarding when no value is provided.
  • Snapshot MTPHelpSnapshotTests.VerifyMTPHelpOutput.verified.txt updated for the new help line.

Follow-up

The full end-to-end JSON output also requires a fix on the MTP side: TerminalOutputDevice.ConsumeAsync and DisplayAfterSessionEndRunAsync currently early-return when _isServerMode is true (which the SDK always sets via --server dotnettestcli), so today MTP buffers/emits no JSON when invoked through dotnet test. I'll file a follow-up issue in microsoft/testfx to address that.

Plumbs the optional `text`/`json` value of `--list-tests` through the
SDK CLI to the underlying Microsoft.Testing.Platform test host. The MTP-side
support for the JSON discovery output was added in
microsoft/testfx#8280; this change exposes it via `dotnet test`.

Fixes #49754

- Switch the MTP `--list-tests` option arity from `Zero` to `ZeroOrOne`,
  restrict accepted values to `text`/`json` via `AcceptOnlyFromAmong`,
  and add a dedicated description resource string.
- Carry the optional value through `TestOptions` and forward it to the
  test host in `TestApplication.GetArguments`.
- Update the MTP help snapshot.
- Add tests covering `--list-tests text`, `--list-tests json`, and
  rejection of invalid values; existing argument-escaping test still
  asserts the bare `--list-tests` token (no value) is forwarded as
  before.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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 adds SDK CLI plumbing for Microsoft.Testing.Platform’s dotnet test --list-tests optional output format, enabling text or json to be forwarded to the test host.

Changes:

  • Updates the MTP --list-tests option to accept text|json and forwards the selected value.
  • Adds test coverage for forwarding valid values and rejecting invalid values.
  • Updates help text, snapshots, and localization resources for the new option description.
Show a summary per file
File Description
src/Cli/Microsoft.DotNet.Cli.Definitions/Commands/Test/TestCommandDefinition.MicrosoftTestingPlatform.cs Changes --list-tests option arity and accepted values.
src/Cli/Microsoft.DotNet.Cli.Definitions/CommandDefinitionStrings.resx Adds MTP-specific list-tests description.
src/Cli/dotnet/Commands/Test/MTP/MicrosoftTestingPlatformTestCommand.cs Reads the optional list-tests value from parsing.
src/Cli/dotnet/Commands/Test/MTP/Options.cs Adds storage for the list-tests argument.
src/Cli/dotnet/Commands/Test/MTP/TestApplication.cs Forwards the list-tests value to the test application.
test/dotnet.Tests/CommandTests/Test/GivenDotnetTestBuildsAndDiscoversTests.cs Adds valid/invalid list-tests argument tests.
test/dotnet.Tests/CommandTests/Test/snapshots/MTPHelpSnapshotTests.VerifyMTPHelpOutput.verified.txt Updates expected help output.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.cs.xlf Adds localized resource entry placeholder.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.de.xlf Adds localized resource entry placeholder.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.es.xlf Adds localized resource entry placeholder.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.fr.xlf Adds localized resource entry placeholder.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.it.xlf Adds localized resource entry placeholder.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.ja.xlf Adds localized resource entry placeholder.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.ko.xlf Adds localized resource entry placeholder.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.pl.xlf Adds localized resource entry placeholder.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.pt-BR.xlf Adds localized resource entry placeholder.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.ru.xlf Adds localized resource entry placeholder.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.tr.xlf Adds localized resource entry placeholder.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.zh-Hans.xlf Adds localized resource entry placeholder.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.zh-Hant.xlf Adds localized resource entry placeholder.

Copilot's findings

  • Files reviewed: 20/20 changed files
  • Comments generated: 1

Comment on lines +123 to +124
Arity = ArgumentArity.ZeroOrOne
}.AcceptOnlyFromAmong(ListTestsTextArgument, ListTestsJsonArgument);
@Evangelink
Copy link
Copy Markdown
Member Author

Moving back to draft so I can double check something.

@Evangelink Evangelink marked this pull request as draft May 29, 2026 07:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow dotnet test --list-tests json

2 participants