diff --git a/src/Cli/dotnet/Commands/CliCommandStrings.resx b/src/Cli/dotnet/Commands/CliCommandStrings.resx
index 2a62ba8ec28d..d55250fa74cc 100644
--- a/src/Cli/dotnet/Commands/CliCommandStrings.resx
+++ b/src/Cli/dotnet/Commands/CliCommandStrings.resx
@@ -2605,4 +2605,16 @@ Proceed?
Tool package download needs confirmation. Run in interactive mode or use the "--yes" command-line option to confirm.{Locked="--yes"}
-
+
+ Specifying a solution for 'dotnet test' should be via '--solution'.
+
+
+ Specifying a project for 'dotnet test' should be via '--project'.
+
+
+ Specifying a directory for 'dotnet test' should be via '--directory'.
+
+
+ Specifying dlls or executables for 'dotnet test' should be via '--test-modules'.
+
+
\ No newline at end of file
diff --git a/src/Cli/dotnet/Commands/Test/TestingPlatformCommand.cs b/src/Cli/dotnet/Commands/Test/TestingPlatformCommand.cs
index 0a72e7d851c4..e30feb765d8c 100644
--- a/src/Cli/dotnet/Commands/Test/TestingPlatformCommand.cs
+++ b/src/Cli/dotnet/Commands/Test/TestingPlatformCommand.cs
@@ -6,12 +6,13 @@
using System.CommandLine;
using Microsoft.DotNet.Cli.Commands.Test.Terminal;
using Microsoft.DotNet.Cli.Extensions;
+using Microsoft.DotNet.Cli.Utils;
using Microsoft.TemplateEngine.Cli.Commands;
using Microsoft.TemplateEngine.Cli.Help;
namespace Microsoft.DotNet.Cli.Commands.Test;
-internal partial class TestingPlatformCommand : Command, ICustomHelp
+internal partial class TestingPlatformCommand : System.CommandLine.Command, ICustomHelp
{
private MSBuildHandler _msBuildHandler;
private TerminalTestReporter _output;
@@ -45,7 +46,8 @@ public int Run(ParseResult parseResult)
private int RunInternal(ParseResult parseResult)
{
ValidationUtility.ValidateMutuallyExclusiveOptions(parseResult);
-
+ ValidationUtility.ValidateSolutionOrProjectOrDirectoryOrModulesArePassedCorrectly(parseResult);
+
PrepareEnvironment(parseResult, out TestOptions testOptions, out int degreeOfParallelism);
InitializeOutput(degreeOfParallelism, parseResult, testOptions.IsHelp);
diff --git a/src/Cli/dotnet/Commands/Test/ValidationUtility.cs b/src/Cli/dotnet/Commands/Test/ValidationUtility.cs
index 105e092e4725..c871933fb5dd 100644
--- a/src/Cli/dotnet/Commands/Test/ValidationUtility.cs
+++ b/src/Cli/dotnet/Commands/Test/ValidationUtility.cs
@@ -53,6 +53,7 @@ static void ValidateOptionsIrrelevantToModulesFilter(ParseResult parseResult)
}
}
}
+
public static bool ValidateBuildPathOptions(BuildOptions buildPathOptions, TerminalTestReporter output)
{
PathOptions pathOptions = buildPathOptions.PathOptions;
@@ -76,6 +77,47 @@ public static bool ValidateBuildPathOptions(BuildOptions buildPathOptions, Termi
return true;
}
+ ///
+ /// Validates that arguments requiring specific command-line switches are used correctly for Microsoft.Testing.Platform.
+ /// Provides helpful error messages when users provide file/directory arguments without proper switches.
+ ///
+ public static void ValidateSolutionOrProjectOrDirectoryOrModulesArePassedCorrectly(ParseResult parseResult)
+ {
+ if (Environment.GetEnvironmentVariable("DOTNET_TEST_DISABLE_SWITCH_VALIDATION") is "true" or "1")
+ {
+ // In case there is a valid case, users can opt-out.
+ // Note that the validation here is added to have a "better" error message for scenarios that will already fail.
+ // So, disabling validation is okay if the user scenario is valid.
+ return;
+ }
+
+ foreach (string token in parseResult.UnmatchedTokens)
+ {
+ // Check for .sln files
+ if ((token.EndsWith(".sln", StringComparison.OrdinalIgnoreCase) ||
+ token.EndsWith(".slnx", StringComparison.OrdinalIgnoreCase)) && File.Exists(token))
+ {
+ throw new GracefulException(CliCommandStrings.TestCommandUseSolution);
+ }
+ else if ((token.EndsWith(".csproj", StringComparison.OrdinalIgnoreCase) ||
+ token.EndsWith(".vbproj", StringComparison.OrdinalIgnoreCase) ||
+ token.EndsWith(".fsproj", StringComparison.OrdinalIgnoreCase)) && File.Exists(token))
+ {
+ throw new GracefulException(CliCommandStrings.TestCommandUseProject);
+ }
+ else if (Directory.Exists(token))
+ {
+ throw new GracefulException(CliCommandStrings.TestCommandUseDirectory);
+ }
+ else if ((token.EndsWith(".dll", StringComparison.OrdinalIgnoreCase) ||
+ token.EndsWith(".exe", StringComparison.OrdinalIgnoreCase)) &&
+ File.Exists(token))
+ {
+ throw new GracefulException(CliCommandStrings.TestCommandUseTestModules);
+ }
+ }
+ }
+
private static bool ValidateSolutionFilePath(string filePath, TerminalTestReporter output)
{
if (!CliConstants.SolutionExtensions.Contains(Path.GetExtension(filePath)))
diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.cs.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.cs.xlf
index 64a073d7c81c..8fb72716f360 100644
--- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.cs.xlf
+++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.cs.xlf
@@ -3015,6 +3015,26 @@ Cílem projektu je více architektur. Pomocí parametru {0} určete, která arch
OUTPUT_DIR
+
+ Specifying a directory for 'dotnet test' should be via '--directory'.
+ Specifying a directory for 'dotnet test' should be via '--directory'.
+
+
+
+ Specifying a project for 'dotnet test' should be via '--project'.
+ Specifying a project for 'dotnet test' should be via '--project'.
+
+
+
+ Specifying a solution for 'dotnet test' should be via '--solution'.
+ Specifying a solution for 'dotnet test' should be via '--solution'.
+
+
+
+ Specifying dlls or executables for 'dotnet test' should be via '--test-modules'.
+ Specifying dlls or executables for 'dotnet test' should be via '--test-modules'.
+
+ The configuration to use for running tests. The default for most projects is 'Debug'.Konfigurace, která se má použít pro spuštění testů. Výchozí možností pro většinu projektů je Debug.
diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.de.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.de.xlf
index 109c182e2e04..614f11f3bb92 100644
--- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.de.xlf
+++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.de.xlf
@@ -3015,6 +3015,26 @@ Ihr Projekt verwendet mehrere Zielframeworks. Geben Sie über "{0}" an, welches
OUTPUT_DIR
+
+ Specifying a directory for 'dotnet test' should be via '--directory'.
+ Specifying a directory for 'dotnet test' should be via '--directory'.
+
+
+
+ Specifying a project for 'dotnet test' should be via '--project'.
+ Specifying a project for 'dotnet test' should be via '--project'.
+
+
+
+ Specifying a solution for 'dotnet test' should be via '--solution'.
+ Specifying a solution for 'dotnet test' should be via '--solution'.
+
+
+
+ Specifying dlls or executables for 'dotnet test' should be via '--test-modules'.
+ Specifying dlls or executables for 'dotnet test' should be via '--test-modules'.
+
+ The configuration to use for running tests. The default for most projects is 'Debug'.Die für die Testausführung zu verwendende Konfiguration. Standard für die meisten Projekte ist "Debug".
diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.es.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.es.xlf
index 4b52ce438a03..67750aa10927 100644
--- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.es.xlf
+++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.es.xlf
@@ -3015,6 +3015,26 @@ Su proyecto tiene como destino varias plataformas. Especifique la que quiere usa
OUTPUT_DIR
+
+ Specifying a directory for 'dotnet test' should be via '--directory'.
+ Specifying a directory for 'dotnet test' should be via '--directory'.
+
+
+
+ Specifying a project for 'dotnet test' should be via '--project'.
+ Specifying a project for 'dotnet test' should be via '--project'.
+
+
+
+ Specifying a solution for 'dotnet test' should be via '--solution'.
+ Specifying a solution for 'dotnet test' should be via '--solution'.
+
+
+
+ Specifying dlls or executables for 'dotnet test' should be via '--test-modules'.
+ Specifying dlls or executables for 'dotnet test' should be via '--test-modules'.
+
+ The configuration to use for running tests. The default for most projects is 'Debug'.La configuración que se usará para ejecutar pruebas. El valor predeterminado para la mayoría de los proyectos es "Debug".
diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.fr.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.fr.xlf
index b82c108765ca..ed1287261435 100644
--- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.fr.xlf
+++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.fr.xlf
@@ -3015,6 +3015,26 @@ Votre projet cible plusieurs frameworks. Spécifiez le framework à exécuter à
OUTPUT_DIR
+
+ Specifying a directory for 'dotnet test' should be via '--directory'.
+ Specifying a directory for 'dotnet test' should be via '--directory'.
+
+
+
+ Specifying a project for 'dotnet test' should be via '--project'.
+ Specifying a project for 'dotnet test' should be via '--project'.
+
+
+
+ Specifying a solution for 'dotnet test' should be via '--solution'.
+ Specifying a solution for 'dotnet test' should be via '--solution'.
+
+
+
+ Specifying dlls or executables for 'dotnet test' should be via '--test-modules'.
+ Specifying dlls or executables for 'dotnet test' should be via '--test-modules'.
+
+ The configuration to use for running tests. The default for most projects is 'Debug'.Configuration à utiliser pour l'exécution des tests. La valeur par défaut pour la plupart des projets est 'Debug'.
diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.it.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.it.xlf
index 36ce6c7bf784..1701ebd139e3 100644
--- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.it.xlf
+++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.it.xlf
@@ -3015,6 +3015,26 @@ Il progetto è destinato a più framework. Specificare il framework da eseguire
OUTPUT_DIR
+
+ Specifying a directory for 'dotnet test' should be via '--directory'.
+ Specifying a directory for 'dotnet test' should be via '--directory'.
+
+
+
+ Specifying a project for 'dotnet test' should be via '--project'.
+ Specifying a project for 'dotnet test' should be via '--project'.
+
+
+
+ Specifying a solution for 'dotnet test' should be via '--solution'.
+ Specifying a solution for 'dotnet test' should be via '--solution'.
+
+
+
+ Specifying dlls or executables for 'dotnet test' should be via '--test-modules'.
+ Specifying dlls or executables for 'dotnet test' should be via '--test-modules'.
+
+ The configuration to use for running tests. The default for most projects is 'Debug'.Configurazione da usare per eseguire i test. L'impostazione predefinita per la maggior parte dei progetti è 'Debug'.
diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.ja.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.ja.xlf
index ec5845275adf..f2dc148710f1 100644
--- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.ja.xlf
+++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.ja.xlf
@@ -3015,6 +3015,26 @@ Your project targets multiple frameworks. Specify which framework to run using '
OUTPUT_DIR
+
+ Specifying a directory for 'dotnet test' should be via '--directory'.
+ Specifying a directory for 'dotnet test' should be via '--directory'.
+
+
+
+ Specifying a project for 'dotnet test' should be via '--project'.
+ Specifying a project for 'dotnet test' should be via '--project'.
+
+
+
+ Specifying a solution for 'dotnet test' should be via '--solution'.
+ Specifying a solution for 'dotnet test' should be via '--solution'.
+
+
+
+ Specifying dlls or executables for 'dotnet test' should be via '--test-modules'.
+ Specifying dlls or executables for 'dotnet test' should be via '--test-modules'.
+
+ The configuration to use for running tests. The default for most projects is 'Debug'.テストの実行に使用する構成。ほとんどのプロジェクトで、既定値は 'Debug' です。
diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.ko.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.ko.xlf
index 24a33bd40fbe..d4f4a6cf2c4f 100644
--- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.ko.xlf
+++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.ko.xlf
@@ -3015,6 +3015,26 @@ Your project targets multiple frameworks. Specify which framework to run using '
OUTPUT_DIR
+
+ Specifying a directory for 'dotnet test' should be via '--directory'.
+ Specifying a directory for 'dotnet test' should be via '--directory'.
+
+
+
+ Specifying a project for 'dotnet test' should be via '--project'.
+ Specifying a project for 'dotnet test' should be via '--project'.
+
+
+
+ Specifying a solution for 'dotnet test' should be via '--solution'.
+ Specifying a solution for 'dotnet test' should be via '--solution'.
+
+
+
+ Specifying dlls or executables for 'dotnet test' should be via '--test-modules'.
+ Specifying dlls or executables for 'dotnet test' should be via '--test-modules'.
+
+ The configuration to use for running tests. The default for most projects is 'Debug'.테스트 실행에 사용할 구성입니다. 대부분의 프로젝트에서 기본값은 'Debug'입니다.
diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.pl.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.pl.xlf
index 3ab929146205..c182bac522b2 100644
--- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.pl.xlf
+++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.pl.xlf
@@ -3015,6 +3015,26 @@ Projekt ma wiele platform docelowych. Określ platformę do uruchomienia przy u
OUTPUT_DIR
+
+ Specifying a directory for 'dotnet test' should be via '--directory'.
+ Specifying a directory for 'dotnet test' should be via '--directory'.
+
+
+
+ Specifying a project for 'dotnet test' should be via '--project'.
+ Specifying a project for 'dotnet test' should be via '--project'.
+
+
+
+ Specifying a solution for 'dotnet test' should be via '--solution'.
+ Specifying a solution for 'dotnet test' should be via '--solution'.
+
+
+
+ Specifying dlls or executables for 'dotnet test' should be via '--test-modules'.
+ Specifying dlls or executables for 'dotnet test' should be via '--test-modules'.
+
+ The configuration to use for running tests. The default for most projects is 'Debug'.Konfiguracja do użycia na potrzeby uruchamiania testów. W przypadku większości projektów ustawienie domyślne to „Debugowanie”.
diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.pt-BR.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.pt-BR.xlf
index c2d3b8d5b224..0ccffd065bf7 100644
--- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.pt-BR.xlf
+++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.pt-BR.xlf
@@ -3015,6 +3015,26 @@ Ele tem diversas estruturas como destino. Especifique que estrutura executar usa
OUTPUT_DIR
+
+ Specifying a directory for 'dotnet test' should be via '--directory'.
+ Specifying a directory for 'dotnet test' should be via '--directory'.
+
+
+
+ Specifying a project for 'dotnet test' should be via '--project'.
+ Specifying a project for 'dotnet test' should be via '--project'.
+
+
+
+ Specifying a solution for 'dotnet test' should be via '--solution'.
+ Specifying a solution for 'dotnet test' should be via '--solution'.
+
+
+
+ Specifying dlls or executables for 'dotnet test' should be via '--test-modules'.
+ Specifying dlls or executables for 'dotnet test' should be via '--test-modules'.
+
+ The configuration to use for running tests. The default for most projects is 'Debug'.A configuração a ser usada para executar testes. O padrão para a maioria dos projetos é 'Debug'.
diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.ru.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.ru.xlf
index 1b9fb6f85c3c..8d99de7d1a82 100644
--- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.ru.xlf
+++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.ru.xlf
@@ -3015,6 +3015,26 @@ Your project targets multiple frameworks. Specify which framework to run using '
OUTPUT_DIR
+
+ Specifying a directory for 'dotnet test' should be via '--directory'.
+ Specifying a directory for 'dotnet test' should be via '--directory'.
+
+
+
+ Specifying a project for 'dotnet test' should be via '--project'.
+ Specifying a project for 'dotnet test' should be via '--project'.
+
+
+
+ Specifying a solution for 'dotnet test' should be via '--solution'.
+ Specifying a solution for 'dotnet test' should be via '--solution'.
+
+
+
+ Specifying dlls or executables for 'dotnet test' should be via '--test-modules'.
+ Specifying dlls or executables for 'dotnet test' should be via '--test-modules'.
+
+ The configuration to use for running tests. The default for most projects is 'Debug'.Конфигурация для выполнения тестов. По умолчанию для большинства проектов используется "Debug".
diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.tr.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.tr.xlf
index 9009d605ee54..3adba7705d9c 100644
--- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.tr.xlf
+++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.tr.xlf
@@ -3015,6 +3015,26 @@ Projeniz birden fazla Framework'ü hedefliyor. '{0}' kullanarak hangi Framework'
OUTPUT_DIR
+
+ Specifying a directory for 'dotnet test' should be via '--directory'.
+ Specifying a directory for 'dotnet test' should be via '--directory'.
+
+
+
+ Specifying a project for 'dotnet test' should be via '--project'.
+ Specifying a project for 'dotnet test' should be via '--project'.
+
+
+
+ Specifying a solution for 'dotnet test' should be via '--solution'.
+ Specifying a solution for 'dotnet test' should be via '--solution'.
+
+
+
+ Specifying dlls or executables for 'dotnet test' should be via '--test-modules'.
+ Specifying dlls or executables for 'dotnet test' should be via '--test-modules'.
+
+ The configuration to use for running tests. The default for most projects is 'Debug'.Testleri çalıştırmak için kullanılacak yapılandırma. Çoğu proje için varsayılan, ‘Hata Ayıklama’ seçeneğidir.
diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hans.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hans.xlf
index f0de7d31f629..b2e5dbe36071 100644
--- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hans.xlf
+++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hans.xlf
@@ -3015,6 +3015,26 @@ Your project targets multiple frameworks. Specify which framework to run using '
OUTPUT_DIR
+
+ Specifying a directory for 'dotnet test' should be via '--directory'.
+ Specifying a directory for 'dotnet test' should be via '--directory'.
+
+
+
+ Specifying a project for 'dotnet test' should be via '--project'.
+ Specifying a project for 'dotnet test' should be via '--project'.
+
+
+
+ Specifying a solution for 'dotnet test' should be via '--solution'.
+ Specifying a solution for 'dotnet test' should be via '--solution'.
+
+
+
+ Specifying dlls or executables for 'dotnet test' should be via '--test-modules'.
+ Specifying dlls or executables for 'dotnet test' should be via '--test-modules'.
+
+ The configuration to use for running tests. The default for most projects is 'Debug'.用于运行测试的配置。大多数项目的默认值是 "Debug"。
diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hant.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hant.xlf
index 6b6ec748e046..44eb22e97724 100644
--- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hant.xlf
+++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hant.xlf
@@ -3015,6 +3015,26 @@ Your project targets multiple frameworks. Specify which framework to run using '
OUTPUT_DIR
+
+ Specifying a directory for 'dotnet test' should be via '--directory'.
+ Specifying a directory for 'dotnet test' should be via '--directory'.
+
+
+
+ Specifying a project for 'dotnet test' should be via '--project'.
+ Specifying a project for 'dotnet test' should be via '--project'.
+
+
+
+ Specifying a solution for 'dotnet test' should be via '--solution'.
+ Specifying a solution for 'dotnet test' should be via '--solution'.
+
+
+
+ Specifying dlls or executables for 'dotnet test' should be via '--test-modules'.
+ Specifying dlls or executables for 'dotnet test' should be via '--test-modules'.
+
+ The configuration to use for running tests. The default for most projects is 'Debug'.要用於執行測試的組態。大部分的專案預設為「偵錯」。
diff --git a/test/dotnet.Tests/CommandTests/Test/TestCommandValidationTests.cs b/test/dotnet.Tests/CommandTests/Test/TestCommandValidationTests.cs
new file mode 100644
index 000000000000..52faf4ced86b
--- /dev/null
+++ b/test/dotnet.Tests/CommandTests/Test/TestCommandValidationTests.cs
@@ -0,0 +1,91 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using Microsoft.DotNet.Tools.Test.Utilities;
+
+namespace Microsoft.DotNet.Cli.Test.Tests
+{
+ public class TestCommandValidationTests : SdkTest
+ {
+ public TestCommandValidationTests(ITestOutputHelper log) : base(log)
+ {
+ }
+
+ [Theory]
+ [InlineData("MySolution.sln", "Specifying a solution for 'dotnet test' should be via '--solution'.")]
+ [InlineData("MyProject.csproj", "Specifying a project for 'dotnet test' should be via '--project'.")]
+ [InlineData("MyProject.vbproj", "Specifying a project for 'dotnet test' should be via '--project'.")]
+ [InlineData("MyProject.fsproj", "Specifying a project for 'dotnet test' should be via '--project'.")]
+ public void TestCommandShouldValidateFileArgumentsAndProvideHelpfulMessages(string filename, string expectedErrorStart)
+ {
+ var testDir = _testAssetsManager.CreateTestDirectory();
+
+ // Create the test file
+ var testFilePath = Path.Combine(testDir.Path, filename);
+ File.WriteAllText(testFilePath, "dummy content");
+ File.WriteAllText(Path.Combine(testDir.Path, "dotnet.config"),
+ """
+ [dotnet.test.runner]
+ name = Microsoft.Testing.Platform
+ """);
+
+ var result = new DotnetTestCommand(Log, disableNewOutput: false)
+ .WithWorkingDirectory(testDir.Path)
+ .Execute(filename);
+
+ result.ExitCode.Should().NotBe(0);
+ if (!TestContext.IsLocalized())
+ {
+ result.StdErr.Should().Contain(expectedErrorStart);
+ }
+ }
+
+ [Fact]
+ public void TestCommandShouldValidateDirectoryArgumentAndProvideHelpfulMessage()
+ {
+ var testDir = _testAssetsManager.CreateTestDirectory();
+ var subDir = Path.Combine(testDir.Path, "test_directory");
+ Directory.CreateDirectory(subDir);
+ File.WriteAllText(Path.Combine(testDir.Path, "dotnet.config"),
+ """
+ [dotnet.test.runner]
+ name = Microsoft.Testing.Platform
+ """);
+
+ var result = new DotnetTestCommand(Log, disableNewOutput: false)
+ .WithWorkingDirectory(testDir.Path)
+ .Execute("test_directory");
+
+ result.ExitCode.Should().NotBe(0);
+ if (!TestContext.IsLocalized())
+ {
+ result.StdErr.Should().Contain("Specifying a directory for 'dotnet test' should be via '--directory'.");
+ }
+ }
+
+ [Fact]
+ public void TestCommandShouldValidateDllArgumentAndProvideHelpfulMessage()
+ {
+ var testDir = _testAssetsManager.CreateTestDirectory();
+
+ // Create a dummy dll file
+ var dllPath = Path.Combine(testDir.Path, "test.dll");
+ File.WriteAllText(dllPath, "dummy dll content");
+ File.WriteAllText(Path.Combine(testDir.Path, "dotnet.config"),
+ """
+ [dotnet.test.runner]
+ name = Microsoft.Testing.Platform
+ """);
+
+ var result = new DotnetTestCommand(Log, disableNewOutput: false)
+ .WithWorkingDirectory(testDir.Path)
+ .Execute("test.dll");
+
+ result.ExitCode.Should().NotBe(0);
+ if (!TestContext.IsLocalized())
+ {
+ result.StdErr.Should().Contain("Specifying dlls or executables for 'dotnet test' should be via '--test-modules'.");
+ }
+ }
+ }
+}