Skip to content

Implement global --config-file and --diagnostic-output-directory options for dotnet test MTP #50136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 11, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/Cli/dotnet/Commands/CliCommandStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,37 @@ This is equivalent to deleting project.assets.json.</value>
<value>The directory where the test results will be placed.
The specified directory will be created if it does not exist.</value>
</data>
<data name="CmdConfigFileDescription" xml:space="preserve">
<value>The NuGet configuration file to use for the test execution.</value>
Copy link
Member

Choose a reason for hiding this comment

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

@copilot Update the description to:

Specifies a testconfig.json file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The description is already set to "Specifies a testconfig.json file." as requested. This was updated in commit 06369bf.

</data>
<data name="CmdConfigFilePath" xml:space="preserve">
<value>CONFIG_FILE</value>
</data>
<data name="CmdDiagnosticOutputDirectoryDescription" xml:space="preserve">
<value>The directory where diagnostic output will be placed.
The specified directory will be created if it does not exist.</value>
</data>
<data name="CmdDiagnosticOutputDirectoryPath" xml:space="preserve">
<value>DIAGNOSTIC_DIR</value>
</data>
<data name="CmdTimeoutDescription" xml:space="preserve">
<value>The timeout for the test execution in milliseconds.</value>
</data>
<data name="CmdTimeoutValue" xml:space="preserve">
<value>TIMEOUT</value>
</data>
<data name="CmdMinimumExpectedTestsDescription" xml:space="preserve">
<value>The minimum number of tests expected to be discovered.</value>
</data>
<data name="CmdMinimumExpectedTestsValue" xml:space="preserve">
<value>COUNT</value>
</data>
<data name="CmdMaximumFailedTestsDescription" xml:space="preserve">
<value>The maximum number of tests allowed to fail before the test run is terminated.</value>
</data>
<data name="CmdMaximumFailedTestsValue" xml:space="preserve">
<value>COUNT</value>
</data>
<data name="CmdRootPathName" xml:space="preserve">
<value>ROOT_PATH</value>
</data>
Expand Down
23 changes: 20 additions & 3 deletions src/Cli/dotnet/Commands/Test/MSBuildUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,28 @@ public static BuildOptions GetBuildOptions(ParseResult parseResult, int degreeOf
string? resultsDirectory = parseResult.GetValue(TestingPlatformOptions.ResultsDirectoryOption);
if (resultsDirectory is not null)
{
resultsDirectory = Path.Combine(Directory.GetCurrentDirectory(), resultsDirectory);
resultsDirectory = Path.GetFullPath(resultsDirectory);
}

string? configFile = parseResult.GetValue(TestingPlatformOptions.ConfigFileOption);
if (configFile is not null)
{
configFile = Path.GetFullPath(configFile);
}

string? diagnosticOutputDirectory = parseResult.GetValue(TestingPlatformOptions.DiagnosticOutputDirectoryOption);
if (diagnosticOutputDirectory is not null)
{
diagnosticOutputDirectory = Path.GetFullPath(diagnosticOutputDirectory);
}

PathOptions pathOptions = new(
parseResult.GetValue(TestingPlatformOptions.ProjectOption),
parseResult.GetValue(TestingPlatformOptions.SolutionOption),
parseResult.GetValue(TestingPlatformOptions.DirectoryOption),
resultsDirectory);
resultsDirectory,
configFile,
diagnosticOutputDirectory);

return new BuildOptions(
pathOptions,
Expand All @@ -87,7 +101,10 @@ public static BuildOptions GetBuildOptions(ParseResult parseResult, int degreeOf
parseResult.GetValue(TestingPlatformOptions.NoLaunchProfileArgumentsOption),
degreeOfParallelism,
otherArgs,
msbuildArgs);
msbuildArgs,
parseResult.GetValue(TestingPlatformOptions.TimeoutOption),
parseResult.GetValue(TestingPlatformOptions.MinimumExpectedTestsOption),
parseResult.GetValue(TestingPlatformOptions.MaximumFailedTestsOption));
}

private static bool BuildOrRestoreProjectOrSolution(string filePath, BuildOptions buildOptions)
Expand Down
10 changes: 7 additions & 3 deletions src/Cli/dotnet/Commands/Test/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Microsoft.DotNet.Cli.Commands.Test;

internal record TestOptions(bool HasFilterMode, bool IsHelp);

internal record PathOptions(string? ProjectPath, string? SolutionPath, string? DirectoryPath, string? ResultsDirectoryPath);
internal record PathOptions(string? ProjectPath, string? SolutionPath, string? DirectoryPath, string? ResultsDirectoryPath, string? ConfigFilePath, string? DiagnosticOutputDirectoryPath);

internal record BuildOptions(
PathOptions PathOptions,
Expand All @@ -14,5 +14,9 @@ internal record BuildOptions(
Utils.VerbosityOptions? Verbosity,
bool NoLaunchProfile,
bool NoLaunchProfileArguments,
int DegreeOfParallelism, List<string> UnmatchedTokens,
IEnumerable<string> MSBuildArgs);
int DegreeOfParallelism,
List<string> UnmatchedTokens,
IEnumerable<string> MSBuildArgs,
string? Timeout,
string? MinimumExpectedTests,
string? MaximumFailedTests);
25 changes: 25 additions & 0 deletions src/Cli/dotnet/Commands/Test/TestApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,31 @@ private string GetArguments(TestOptions testOptions)
builder.Append($" {TestingPlatformOptions.ResultsDirectoryOption.Name} {ArgumentEscaper.EscapeSingleArg(resultsDirectoryPath)}");
}

if (_buildOptions.PathOptions.ConfigFilePath is { } configFilePath)
{
builder.Append($" {TestingPlatformOptions.ConfigFileOption.Name} {ArgumentEscaper.EscapeSingleArg(configFilePath)}");
}

if (_buildOptions.PathOptions.DiagnosticOutputDirectoryPath is { } diagnosticOutputDirectoryPath)
{
builder.Append($" {TestingPlatformOptions.DiagnosticOutputDirectoryOption.Name} {ArgumentEscaper.EscapeSingleArg(diagnosticOutputDirectoryPath)}");
}

if (_buildOptions.Timeout is { } timeout)
{
builder.Append($" {TestingPlatformOptions.TimeoutOption.Name} {ArgumentEscaper.EscapeSingleArg(timeout)}");
}

if (_buildOptions.MinimumExpectedTests is { } minimumExpectedTests)
{
builder.Append($" {TestingPlatformOptions.MinimumExpectedTestsOption.Name} {ArgumentEscaper.EscapeSingleArg(minimumExpectedTests)}");
}

if (_buildOptions.MaximumFailedTests is { } maximumFailedTests)
{
builder.Append($" {TestingPlatformOptions.MaximumFailedTestsOption.Name} {ArgumentEscaper.EscapeSingleArg(maximumFailedTests)}");
}

foreach (var arg in _buildOptions.UnmatchedTokens)
{
builder.Append($" {ArgumentEscaper.EscapeSingleArg(arg)}");
Expand Down
5 changes: 5 additions & 0 deletions src/Cli/dotnet/Commands/Test/TestCommandParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,11 @@ private static Command GetTestingPlatformCliCommand()
command.Options.Add(TestingPlatformOptions.TestModulesFilterOption);
command.Options.Add(TestingPlatformOptions.TestModulesRootDirectoryOption);
command.Options.Add(TestingPlatformOptions.ResultsDirectoryOption);
command.Options.Add(TestingPlatformOptions.ConfigFileOption);
command.Options.Add(TestingPlatformOptions.DiagnosticOutputDirectoryOption);
command.Options.Add(TestingPlatformOptions.TimeoutOption);
command.Options.Add(TestingPlatformOptions.MinimumExpectedTestsOption);
command.Options.Add(TestingPlatformOptions.MaximumFailedTestsOption);
command.Options.Add(TestingPlatformOptions.MaxParallelTestModulesOption);
command.Options.Add(CommonOptions.ArchitectureOption);
command.Options.Add(CommonOptions.PropertiesOption);
Expand Down
35 changes: 35 additions & 0 deletions src/Cli/dotnet/Commands/Test/TestingPlatformOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,41 @@ internal static class TestingPlatformOptions
Arity = ArgumentArity.ExactlyOne
};

public static readonly Option<string> ConfigFileOption = new("--config-file")
{
Description = CliCommandStrings.CmdConfigFileDescription,
HelpName = CliCommandStrings.CmdConfigFilePath,
Arity = ArgumentArity.ExactlyOne
};

public static readonly Option<string> DiagnosticOutputDirectoryOption = new("--diagnostic-output-directory")
{
Description = CliCommandStrings.CmdDiagnosticOutputDirectoryDescription,
HelpName = CliCommandStrings.CmdDiagnosticOutputDirectoryPath,
Arity = ArgumentArity.ExactlyOne
};

public static readonly Option<string> TimeoutOption = new("--timeout")
{
Description = CliCommandStrings.CmdTimeoutDescription,
HelpName = CliCommandStrings.CmdTimeoutValue,
Arity = ArgumentArity.ExactlyOne
};

public static readonly Option<string> MinimumExpectedTestsOption = new("--minimum-expected-tests")
{
Description = CliCommandStrings.CmdMinimumExpectedTestsDescription,
HelpName = CliCommandStrings.CmdMinimumExpectedTestsValue,
Arity = ArgumentArity.ExactlyOne
};

public static readonly Option<string> MaximumFailedTestsOption = new("--maximum-failed-tests")
{
Description = CliCommandStrings.CmdMaximumFailedTestsDescription,
HelpName = CliCommandStrings.CmdMaximumFailedTestsValue,
Arity = ArgumentArity.ExactlyOne
};

public static readonly Option<string> MaxParallelTestModulesOption = new("--max-parallel-test-modules")
{
Description = CliCommandStrings.CmdMaxParallelTestModulesDescription,
Expand Down
52 changes: 52 additions & 0 deletions src/Cli/dotnet/Commands/xlf/CliCommandStrings.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 52 additions & 0 deletions src/Cli/dotnet/Commands/xlf/CliCommandStrings.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading