diff --git a/src/Cli/dotnet/commands/dotnet-test/CliConstants.cs b/src/Cli/dotnet/commands/dotnet-test/CliConstants.cs
index 08ba9c16b3dc..b900c7f6f459 100644
--- a/src/Cli/dotnet/commands/dotnet-test/CliConstants.cs
+++ b/src/Cli/dotnet/commands/dotnet-test/CliConstants.cs
@@ -15,6 +15,11 @@ internal static class CliConstants
public const string MSBuildExeName = "MSBuild.dll";
public const string ParametersSeparator = "--";
+
+ public const string VSTest = "VSTest";
+ public const string MicrosoftTestingPlatform = "MicrosoftTestingPlatform";
+
+ public const string TestSectionKey = "test";
}
internal static class TestStates
diff --git a/src/Cli/dotnet/commands/dotnet-test/LocalizableStrings.resx b/src/Cli/dotnet/commands/dotnet-test/LocalizableStrings.resx
index 2a6adfc6f413..97836d0b308a 100644
--- a/src/Cli/dotnet/commands/dotnet-test/LocalizableStrings.resx
+++ b/src/Cli/dotnet/commands/dotnet-test/LocalizableStrings.resx
@@ -326,4 +326,7 @@ Examples:
Test application(s) that support VSTest are not supported.
+
+ Test runner '{0}' is not supported
+
diff --git a/src/Cli/dotnet/commands/dotnet-test/TestCommandParser.cs b/src/Cli/dotnet/commands/dotnet-test/TestCommandParser.cs
index 5196981af9ae..07294197c416 100644
--- a/src/Cli/dotnet/commands/dotnet-test/TestCommandParser.cs
+++ b/src/Cli/dotnet/commands/dotnet-test/TestCommandParser.cs
@@ -2,7 +2,10 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System.CommandLine;
+using System.Text.Json;
+using System.Text.Json.Nodes;
using Microsoft.DotNet.Tools.Test;
+using Microsoft.NET.Sdk.WorkloadManifestReader;
using LocalizableStrings = Microsoft.DotNet.Tools.Test.LocalizableStrings;
namespace Microsoft.DotNet.Cli
@@ -152,18 +155,42 @@ private static CliOption CreateBlameHangDumpOption()
private static readonly CliCommand Command = ConstructCommand();
-
-
public static CliCommand GetCommand()
{
return Command;
}
- private static bool IsTestingPlatformEnabled()
+ private static string GetTestRunnerName()
{
- var testingPlatformEnabledEnvironmentVariable = Environment.GetEnvironmentVariable("DOTNET_CLI_TESTINGPLATFORM_ENABLE");
- var isTestingPlatformEnabled = testingPlatformEnabledEnvironmentVariable == "1" || string.Equals(testingPlatformEnabledEnvironmentVariable, "true", StringComparison.OrdinalIgnoreCase);
- return isTestingPlatformEnabled;
+ string defaultTestRunnerName = CliConstants.VSTest;
+
+ string? globalJsonPath = SdkDirectoryWorkloadManifestProvider.GetGlobalJsonPath(Environment.CurrentDirectory);
+
+ if (string.IsNullOrEmpty(globalJsonPath))
+ {
+ return defaultTestRunnerName;
+ }
+
+ JsonNode globalJson = JsonObject.Parse(File.ReadAllText(globalJsonPath));
+ JsonNode? testSection = globalJson[CliConstants.TestSectionKey];
+
+ if (testSection is null)
+ {
+ return defaultTestRunnerName;
+ }
+
+ JsonSerializerOptions JsonSerializerOptions = new JsonSerializerOptions
+ {
+ PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
+ };
+ var testSettings = JsonSerializer.Deserialize(testSection, JsonSerializerOptions);
+
+ if (testSettings?.Runner?.Name is not null)
+ {
+ return testSettings.Runner.Name;
+ }
+
+ return defaultTestRunnerName;
}
private static CliCommand ConstructCommand()
@@ -171,19 +198,18 @@ private static CliCommand ConstructCommand()
#if RELEASE
return GetVSTestCliCommand();
#else
- bool isTestingPlatformEnabled = IsTestingPlatformEnabled();
- string testingSdkName = isTestingPlatformEnabled ? "testingplatform" : "vstest";
+ string testRunnerName = GetTestRunnerName();
- if (isTestingPlatformEnabled)
+ if (testRunnerName.Equals(CliConstants.VSTest, StringComparison.OrdinalIgnoreCase))
{
- return GetTestingPlatformCliCommand();
+ return GetVSTestCliCommand();
}
- else
+ else if (testRunnerName.Equals(CliConstants.MicrosoftTestingPlatform, StringComparison.OrdinalIgnoreCase))
{
- return GetVSTestCliCommand();
+ return GetTestingPlatformCliCommand();
}
- throw new InvalidOperationException($"Testing sdk not supported: {testingSdkName}");
+ throw new InvalidOperationException(string.Format(LocalizableStrings.CmdUnsupportedTestRunnerDescription, testRunnerName));
#endif
}
diff --git a/src/Cli/dotnet/commands/dotnet-test/TestSettings.cs b/src/Cli/dotnet/commands/dotnet-test/TestSettings.cs
new file mode 100644
index 000000000000..7d99137837e4
--- /dev/null
+++ b/src/Cli/dotnet/commands/dotnet-test/TestSettings.cs
@@ -0,0 +1,8 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+namespace Microsoft.DotNet.Cli
+{
+ internal sealed record TestSettings(Runner? Runner);
+ internal sealed record Runner(string Name);
+}
diff --git a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.cs.xlf b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.cs.xlf
index 2ad19fb0b1b8..f574980e7d06 100644
--- a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.cs.xlf
+++ b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.cs.xlf
@@ -255,6 +255,11 @@ Pokud zadaný adresář neexistuje, bude vytvořen.
Message Request type '{0}' is unsupported.{0} - message request type
+
+ Test runner '{0}' is not supported
+ Test runner '{0}' is not supported
+
+ Test application(s) that support VSTest are not supported.Test application(s) that support VSTest are not supported.
diff --git a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.de.xlf b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.de.xlf
index 230a26c4cdf8..c633271293ca 100644
--- a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.de.xlf
+++ b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.de.xlf
@@ -255,6 +255,11 @@ Das angegebene Verzeichnis wird erstellt, wenn es nicht vorhanden ist.
Message Request type '{0}' is unsupported.{0} - message request type
+
+ Test runner '{0}' is not supported
+ Test runner '{0}' is not supported
+
+ Test application(s) that support VSTest are not supported.Test application(s) that support VSTest are not supported.
diff --git a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.es.xlf b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.es.xlf
index b4504cd41ca0..2b259c0ed1a0 100644
--- a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.es.xlf
+++ b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.es.xlf
@@ -257,6 +257,11 @@ Si no existe, se creará el directorio especificado.
Message Request type '{0}' is unsupported.{0} - message request type
+
+ Test runner '{0}' is not supported
+ Test runner '{0}' is not supported
+
+ Test application(s) that support VSTest are not supported.Test application(s) that support VSTest are not supported.
diff --git a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.fr.xlf b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.fr.xlf
index 080d51785fda..6d5567190efe 100644
--- a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.fr.xlf
+++ b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.fr.xlf
@@ -255,6 +255,11 @@ Le répertoire spécifié est créé, s'il n'existe pas déjà.
Message Request type '{0}' is unsupported.{0} - message request type
+
+ Test runner '{0}' is not supported
+ Test runner '{0}' is not supported
+
+ Test application(s) that support VSTest are not supported.Test application(s) that support VSTest are not supported.
diff --git a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.it.xlf b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.it.xlf
index 31ea56d050fe..bf1222233df1 100644
--- a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.it.xlf
+++ b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.it.xlf
@@ -255,6 +255,11 @@ Se non esiste, la directory specificata verrà creata.
Message Request type '{0}' is unsupported.{0} - message request type
+
+ Test runner '{0}' is not supported
+ Test runner '{0}' is not supported
+
+ Test application(s) that support VSTest are not supported.Test application(s) that support VSTest are not supported.
diff --git a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.ja.xlf b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.ja.xlf
index cc1420582f48..93d03e343f06 100644
--- a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.ja.xlf
+++ b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.ja.xlf
@@ -255,6 +255,11 @@ The specified directory will be created if it does not exist.
Message Request type '{0}' is unsupported.{0} - message request type
+
+ Test runner '{0}' is not supported
+ Test runner '{0}' is not supported
+
+ Test application(s) that support VSTest are not supported.Test application(s) that support VSTest are not supported.
diff --git a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.ko.xlf b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.ko.xlf
index 37bb82ef49af..d04a3cd2ff1d 100644
--- a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.ko.xlf
+++ b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.ko.xlf
@@ -255,6 +255,11 @@ The specified directory will be created if it does not exist.
Message Request type '{0}' is unsupported.{0} - message request type
+
+ Test runner '{0}' is not supported
+ Test runner '{0}' is not supported
+
+ Test application(s) that support VSTest are not supported.Test application(s) that support VSTest are not supported.
diff --git a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.pl.xlf b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.pl.xlf
index 8d40d724227b..49da0c84fc1c 100644
--- a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.pl.xlf
+++ b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.pl.xlf
@@ -255,6 +255,11 @@ Jeśli określony katalog nie istnieje, zostanie utworzony.
Message Request type '{0}' is unsupported.{0} - message request type
+
+ Test runner '{0}' is not supported
+ Test runner '{0}' is not supported
+
+ Test application(s) that support VSTest are not supported.Test application(s) that support VSTest are not supported.
diff --git a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.pt-BR.xlf b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.pt-BR.xlf
index 5eaa4668710e..770f44cee1aa 100644
--- a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.pt-BR.xlf
+++ b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.pt-BR.xlf
@@ -255,6 +255,11 @@ O diretório especificado será criado se ele ainda não existir.
Message Request type '{0}' is unsupported.{0} - message request type
+
+ Test runner '{0}' is not supported
+ Test runner '{0}' is not supported
+
+ Test application(s) that support VSTest are not supported.Test application(s) that support VSTest are not supported.
diff --git a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.ru.xlf b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.ru.xlf
index a9669d9915c4..ae1fe905c186 100644
--- a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.ru.xlf
+++ b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.ru.xlf
@@ -255,6 +255,11 @@ The specified directory will be created if it does not exist.
Message Request type '{0}' is unsupported.{0} - message request type
+
+ Test runner '{0}' is not supported
+ Test runner '{0}' is not supported
+
+ Test application(s) that support VSTest are not supported.Test application(s) that support VSTest are not supported.
diff --git a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.tr.xlf b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.tr.xlf
index 68bcd480e31b..369defc5ef77 100644
--- a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.tr.xlf
+++ b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.tr.xlf
@@ -255,6 +255,11 @@ Belirtilen dizin yoksa oluşturulur.
Message Request type '{0}' is unsupported.{0} - message request type
+
+ Test runner '{0}' is not supported
+ Test runner '{0}' is not supported
+
+ Test application(s) that support VSTest are not supported.Test application(s) that support VSTest are not supported.
diff --git a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.zh-Hans.xlf b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.zh-Hans.xlf
index e7ac40be829b..c6fdfe9b0dc8 100644
--- a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.zh-Hans.xlf
+++ b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.zh-Hans.xlf
@@ -255,6 +255,11 @@ The specified directory will be created if it does not exist.
Message Request type '{0}' is unsupported.{0} - message request type
+
+ Test runner '{0}' is not supported
+ Test runner '{0}' is not supported
+
+ Test application(s) that support VSTest are not supported.Test application(s) that support VSTest are not supported.
diff --git a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.zh-Hant.xlf b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.zh-Hant.xlf
index 222eb321c2c4..01e15d84cb19 100644
--- a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.zh-Hant.xlf
+++ b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.zh-Hant.xlf
@@ -255,6 +255,11 @@ The specified directory will be created if it does not exist.
Message Request type '{0}' is unsupported.{0} - message request type
+
+ Test runner '{0}' is not supported
+ Test runner '{0}' is not supported
+
+ Test application(s) that support VSTest are not supported.Test application(s) that support VSTest are not supported.