diff --git a/src/TestFramework/TestFramework/Assertions/Assert.Fail.cs b/src/TestFramework/TestFramework/Assertions/Assert.Fail.cs index e377044d5a..b5558784f3 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.Fail.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.Fail.cs @@ -24,6 +24,9 @@ public sealed partial class Assert public static void Fail(string message = "") { TelemetryCollector.TrackAssertionCall("Assert.Fail"); - ThrowAssertFailed("Assert.Fail", BuildUserMessage(message)); + + StructuredAssertionMessage structured = new(string.Empty); + structured.WithUserMessage(message); + ThrowAssertFailed(structured); } } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.Inconclusive.cs b/src/TestFramework/TestFramework/Assertions/Assert.Inconclusive.cs index ecd743b0c9..af463176e3 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.Inconclusive.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.Inconclusive.cs @@ -26,7 +26,9 @@ public static void Inconclusive(string message = "") TelemetryCollector.TrackAssertionCall("Assert.Inconclusive"); string userMessage = BuildUserMessage(message); - throw new AssertInconclusiveException( - FormatAssertionFailed("Assert.Inconclusive", userMessage)); + throw new AssertInconclusiveException(FormatInconclusive(userMessage)); } + + private static string FormatInconclusive(string? message) + => FormatPrefixAndMessage(FrameworkMessages.InconclusivePrefix, message); } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.cs b/src/TestFramework/TestFramework/Assertions/Assert.cs index 58da1d5525..daa9c365f0 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.cs @@ -248,13 +248,16 @@ private static string NormalizeCallSitePlaceholder(string placeholderOrParamName private static string FormatAssertionFailed(string assertionName, string? message) { string failedMessage = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.AssertionFailed, assertionName); - return string.IsNullOrWhiteSpace(message) - ? failedMessage - : message![0] is '\n' or '\r' - ? string.Concat(failedMessage, message) - : $"{failedMessage} {message}"; + return FormatPrefixAndMessage(failedMessage, message); } + private static string FormatPrefixAndMessage(string prefix, string? message) + => string.IsNullOrWhiteSpace(message) + ? prefix + : message![0] is '\n' or '\r' + ? string.Concat(prefix, message) + : $"{prefix} {message}"; + /// /// Builds the formatted message using the given user format message and parameters. /// diff --git a/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx b/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx index 23f252636a..53794d770c 100644 --- a/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx +++ b/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx @@ -289,6 +289,9 @@ Actual: {2} {0} failed. + + Assert.Inconclusive. + {0} Expected type:<{1}>. Actual type:<{2}>. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.cs.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.cs.xlf index 60b8fae859..7df8e72e87 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.cs.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.cs.xlf @@ -472,6 +472,11 @@ Skutečnost: {2} Expected collection to contain a specific number of elements. + + Assert.Inconclusive. + Assert.Inconclusive. + + The property 'TestContext.{0}' is related to current test is not available during assembly or class fixtures. Vlastnost TestContext.{0} souvisí s aktuálním testem a není k dispozici během sestavení nebo používání testovacích přípravků tříd. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.de.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.de.xlf index 1e6b7cbb51..8e6e4185da 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.de.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.de.xlf @@ -472,6 +472,11 @@ Tatsächlich: {2} Expected collection to contain a specific number of elements. + + Assert.Inconclusive. + Assert.Inconclusive. + + The property 'TestContext.{0}' is related to current test is not available during assembly or class fixtures. Die Eigenschaft „TestContext.{0}“ im Zusammenhang mit dem aktuellen Test steht während Assembly- oder Klassenfixierungen nicht zur Verfügung. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.es.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.es.xlf index ea21c91a90..76b764f6cf 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.es.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.es.xlf @@ -472,6 +472,11 @@ Real: {2} Expected collection to contain a specific number of elements. + + Assert.Inconclusive. + Assert.Inconclusive. + + The property 'TestContext.{0}' is related to current test is not available during assembly or class fixtures. La propiedad "TestContext.{0}" está relacionado con la prueba actual y no está disponible durante los accesorios de ensamblado o clase. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.fr.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.fr.xlf index 4715630d51..6b531d6516 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.fr.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.fr.xlf @@ -472,6 +472,11 @@ Réel : {2} Expected collection to contain a specific number of elements. + + Assert.Inconclusive. + Assert.Inconclusive. + + The property 'TestContext.{0}' is related to current test is not available during assembly or class fixtures. La propriété « TestContext.{0} », liée au test en cours, n’est pas disponible pendant les fixtures d’assembly ou de classe. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.it.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.it.xlf index ec9ba3f57c..d4ead1a1fa 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.it.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.it.xlf @@ -472,6 +472,11 @@ Effettivo: {2} Expected collection to contain a specific number of elements. + + Assert.Inconclusive. + Assert.Inconclusive. + + The property 'TestContext.{0}' is related to current test is not available during assembly or class fixtures. La proprietà 'TestContext.{0}' relativa al test corrente non è disponibile durante le fixture di assembly o classe. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ja.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ja.xlf index 67eb1ffd04..b638f995a8 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ja.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ja.xlf @@ -472,6 +472,11 @@ Actual: {2} Expected collection to contain a specific number of elements. + + Assert.Inconclusive. + Assert.Inconclusive. + + The property 'TestContext.{0}' is related to current test is not available during assembly or class fixtures. プロパティ 'TestContext.{0}' は現在のテストに関連しており、アセンブリまたはクラス フィクスチャの間は使用できません。 diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ko.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ko.xlf index 317e8b52b1..9b542cd3e1 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ko.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ko.xlf @@ -472,6 +472,11 @@ Actual: {2} Expected collection to contain a specific number of elements. + + Assert.Inconclusive. + Assert.Inconclusive. + + The property 'TestContext.{0}' is related to current test is not available during assembly or class fixtures. 현재 테스트와 관련된 'TestContext.{0}' 속성은 어셈블리나 클래스 픽스처 실행 중에는 사용할 수 없습니다. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pl.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pl.xlf index 97712516ee..7eebba06d1 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pl.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pl.xlf @@ -472,6 +472,11 @@ Rzeczywiste: {2} Expected collection to contain a specific number of elements. + + Assert.Inconclusive. + Assert.Inconclusive. + + The property 'TestContext.{0}' is related to current test is not available during assembly or class fixtures. Właściwość „TestContext.{0}” jest powiązana z bieżącym testem i nie jest dostępna podczas montażu lub konfiguracji klasy. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pt-BR.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pt-BR.xlf index b590bbeb3b..676c1622a3 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pt-BR.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pt-BR.xlf @@ -472,6 +472,11 @@ Real: {2} Expected collection to contain a specific number of elements. + + Assert.Inconclusive. + Assert.Inconclusive. + + The property 'TestContext.{0}' is related to current test is not available during assembly or class fixtures. A propriedade "TestContext.{0}" está relacionada ao teste atual não está disponível durante os acessórios de assembly ou classe. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ru.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ru.xlf index 550a0ebb53..b1a797df9e 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ru.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ru.xlf @@ -472,6 +472,11 @@ Actual: {2} Expected collection to contain a specific number of elements. + + Assert.Inconclusive. + Assert.Inconclusive. + + The property 'TestContext.{0}' is related to current test is not available during assembly or class fixtures. Свойство "TestContext.{0}" связано с текущим тестом и недоступно во время выполнения средств тестирования сборок или классов. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.tr.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.tr.xlf index 71f9d77c64..8b795391cc 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.tr.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.tr.xlf @@ -472,6 +472,11 @@ Gerçekte olan: {2} Expected collection to contain a specific number of elements. + + Assert.Inconclusive. + Assert.Inconclusive. + + The property 'TestContext.{0}' is related to current test is not available during assembly or class fixtures. 'TestContext.{0}' özelliği, derleme veya sınıf sabitlemeleri sırasında mevcut testle ilişkili değildir. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hans.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hans.xlf index 46f72a485f..28e9e3fad0 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hans.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hans.xlf @@ -472,6 +472,11 @@ Actual: {2} Expected collection to contain a specific number of elements. + + Assert.Inconclusive. + Assert.Inconclusive. + + The property 'TestContext.{0}' is related to current test is not available during assembly or class fixtures. 属性‘TestContext.{0}’与当前测试相关,在程序集或类固定例程期间不可用。 diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hant.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hant.xlf index 2d86257a14..99595530c5 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hant.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hant.xlf @@ -472,6 +472,11 @@ Actual: {2} Expected collection to contain a specific number of elements. + + Assert.Inconclusive. + Assert.Inconclusive. + + The property 'TestContext.{0}' is related to current test is not available during assembly or class fixtures. 屬性 'TestContext.{0}' 與目前測試相關,無法在組件或類別測試夾具期間使用。 diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/GenericTestMethodTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/GenericTestMethodTests.cs index 6581de34dc..76b083f269 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/GenericTestMethodTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/GenericTestMethodTests.cs @@ -27,13 +27,13 @@ public async Task TestDifferentGenericMethodTestCases() The generic test method 'NonParameterizedTestMethod' doesn't have arguments, so the generic parameter cannot be inferred\. .+? failed ParameterizedMethodSimple \(1\) \((\d+s )?\d+ms\) - Assert\.Fail failed\. Test method 'ParameterizedMethodSimple' did run with parameter '1' and type 'System\.Byte'\. + Assertion failed\.[\r\n]+\s+Test method 'ParameterizedMethodSimple' did run with parameter '1' and type 'System\.Byte'\. .+? failed ParameterizedMethodSimple \(2\) \((\d+s )?\d+ms\) - Assert\.Fail failed\. Test method 'ParameterizedMethodSimple' did run with parameter '2' and type 'System\.Int32'\. + Assertion failed\.[\r\n]+\s+Test method 'ParameterizedMethodSimple' did run with parameter '2' and type 'System\.Int32'\. .+? failed ParameterizedMethodSimple \("Hello world"\) \((\d+s )?\d+ms\) - Assert\.Fail failed\. Test method 'ParameterizedMethodSimple' did run with parameter 'Hello world' and type 'System\.String'\. + Assertion failed\.[\r\n]+\s+Test method 'ParameterizedMethodSimple' did run with parameter 'Hello world' and type 'System\.String'\. .+? failed ParameterizedMethodSimple \(null\) \((\d+s )?\d+ms\) Test method TestClass\.ParameterizedMethodSimple threw exception: @@ -44,7 +44,7 @@ public async Task TestDifferentGenericMethodTestCases() System\.InvalidOperationException: Found two conflicting types for generic parameter 'T2'\. The conflicting types are 'System\.Byte' and 'System\.Int32'\. .+? failed ParameterizedMethodTwoGenericParametersAndFourMethodParameters \(null,"Hello world","Hello again",3\) \((\d+s )?\d+ms\) - Assert\.Fail failed\. Test method 'ParameterizedMethodTwoGenericParametersAndFourMethodParameters' did run with parameters '', 'Hello world', 'Hello again', '3' and generic types 'System\.Int32', 'System\.String'\. + Assertion failed\.[\r\n]+\s+Test method 'ParameterizedMethodTwoGenericParametersAndFourMethodParameters' did run with parameters '', 'Hello world', 'Hello again', '3' and generic types 'System\.Int32', 'System\.String'\. .+? failed ParameterizedMethodTwoGenericParametersAndFourMethodParameters \("Hello hello","Hello world",null,null\) \((\d+s )?\d+ms\) Test method TestClass\.ParameterizedMethodTwoGenericParametersAndFourMethodParameters threw exception: @@ -70,10 +70,10 @@ Cannot create an instance of T\[] because Type\.ContainsGenericParameters is tru Cannot create an instance of T\[] because Type\.ContainsGenericParameters is true\. .+? failed ParameterizedMethodWithNestedGeneric \(System\.Collections\.Generic\.List`1\[System.String],System\.Collections\.Generic\.List`1\[System.String]\) \((\d+s )?\d+ms\) - Assert\.Fail failed\. Test method 'ParameterizedMethodWithNestedGeneric' did run with first list \[Hello, World] and second list \[Unit, Testing] + Assertion failed\.[\r\n]+\s+Test method 'ParameterizedMethodWithNestedGeneric' did run with first list \[Hello, World] and second list \[Unit, Testing] .+? failed ParameterizedMethodWithNestedGeneric \(System\.Collections\.Generic\.List`1\[System.Int32],System\.Collections\.Generic\.List`1\[System.Int32]\) \((\d+s )?\d+ms\) - Assert\.Fail failed\. Test method 'ParameterizedMethodWithNestedGeneric' did run with first list \[0, 1] and second list \[2, 3] + Assertion failed\.[\r\n]+\s+Test method 'ParameterizedMethodWithNestedGeneric' did run with first list \[0, 1] and second list \[2, 3] .+? """, RegexOptions.Singleline); } diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/RetryTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/RetryTests.cs index 4d8ff10a08..3305922e2a 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/RetryTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/RetryTests.cs @@ -26,7 +26,8 @@ TestMethod5 executed 4 times. """); testHostResult.AssertOutputContains("failed TestMethod5"); - testHostResult.AssertOutputContains("Assert.Fail failed. Failing TestMethod4. Attempts: 4 (from TestContext: 4)"); + testHostResult.AssertOutputMatchesRegex( + """Assertion failed\.[\r\n]+\s+Failing TestMethod4\. Attempts: 4 \(from TestContext: 4\)"""); testHostResult.AssertOutputContainsSummary(failed: 1, passed: 4, skipped: 0); } diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/STAThreadingTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/STAThreadingTests.cs index 0dee5f04b5..7959756b12 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/STAThreadingTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/STAThreadingTests.cs @@ -16,14 +16,9 @@ public sealed class STAThreadingTests : AcceptanceTestBase(); @@ -162,7 +162,7 @@ public async Task RunAssemblyInitializeShouldThrowTestFailedExceptionWithInconcl var exception = (await _testAssemblyInfo.RunAssemblyInitializeAsync(_testContext)).TestFailureException as TestFailedException; exception.Should().NotBeNull(); exception.Outcome.Should().Be(UnitTestOutcome.Inconclusive); - exception.Message.Should().Be("Assembly Initialization method Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestAssemblyInfoTests+DummyTestClass.AssemblyInitializeMethod threw exception. Microsoft.VisualStudio.TestTools.UnitTesting.AssertInconclusiveException: Assert.Inconclusive failed. Test Inconclusive. Aborting test execution."); + exception.Message.Should().Be("Assembly Initialization method Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestAssemblyInfoTests+DummyTestClass.AssemblyInitializeMethod threw exception. Microsoft.VisualStudio.TestTools.UnitTesting.AssertInconclusiveException: Assert.Inconclusive. Test Inconclusive. Aborting test execution."); exception.StackTraceInformation!.ErrorStackTrace.Should().Contain( "Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestAssemblyInfoTests.DummyTestClass.AssemblyInitializeMethod"); exception.InnerException.Should().BeOfType(); @@ -264,7 +264,7 @@ public async Task RunAssemblyCleanupShouldReturnAssertFailureExceptionDetails() _testAssemblyInfo.AssemblyCleanupMethod = typeof(DummyTestClass).GetMethod("AssemblyCleanupMethod")!; string? actualErrorMessage = (await _testAssemblyInfo.ExecuteAssemblyCleanupAsync(GetTestContext()))?.Message; actualErrorMessage!.StartsWith( - "Assembly Cleanup method DummyTestClass.AssemblyCleanupMethod failed. Error Message: Assert.Fail failed. Test Failure..", StringComparison.Ordinal).Should().BeTrue($"Value: {actualErrorMessage}"); + $"Assembly Cleanup method DummyTestClass.AssemblyCleanupMethod failed. Error Message: Assertion failed.{Environment.NewLine}Test Failure..", StringComparison.Ordinal).Should().BeTrue($"Value: {actualErrorMessage}"); } public async Task RunAssemblyCleanupShouldReturnAssertInconclusiveExceptionDetails() @@ -276,7 +276,7 @@ public async Task RunAssemblyCleanupShouldReturnAssertInconclusiveExceptionDetai _testAssemblyInfo.AssemblyCleanupMethod = typeof(DummyTestClass).GetMethod("AssemblyCleanupMethod")!; string? actualErrorMessage = (await _testAssemblyInfo.ExecuteAssemblyCleanupAsync(GetTestContext()))?.Message; actualErrorMessage!.StartsWith( - "Assembly Cleanup method DummyTestClass.AssemblyCleanupMethod failed. Error Message: Assert.Inconclusive failed. Test Inconclusive..", StringComparison.Ordinal).Should().BeTrue($"Value: {actualErrorMessage}"); + "Assembly Cleanup method DummyTestClass.AssemblyCleanupMethod failed. Error Message: Assert.Inconclusive. Test Inconclusive..", StringComparison.Ordinal).Should().BeTrue($"Value: {actualErrorMessage}"); } public async Task RunAssemblyCleanupShouldReturnExceptionDetailsOfNonAssertExceptions() diff --git a/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestClassInfoTests.cs b/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestClassInfoTests.cs index 1db8a177bc..10ba7e293e 100644 --- a/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestClassInfoTests.cs +++ b/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestClassInfoTests.cs @@ -350,7 +350,7 @@ public void RunClassInitializeShouldThrowTestFailedExceptionOnAssertionFailure() exception.Should().NotBeNull(); exception.Outcome.Should().Be(UnitTestOutcome.Failed); - exception.Message.Should().Be("Class Initialization method Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests+DummyTestClass.ClassInitializeMethod threw exception. Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException: Assert.Fail failed. Test failure."); + exception.Message.Should().Be($"Class Initialization method Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests+DummyTestClass.ClassInitializeMethod threw exception. Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException: Assertion failed.{Environment.NewLine}Test failure."); exception.StackTraceInformation!.ErrorStackTrace.Contains( "Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests.DummyTestClass.ClassInitializeMethod", StringComparison.Ordinal).Should().BeTrue(); exception.InnerException.Should().BeOfType(); @@ -367,7 +367,7 @@ public void RunClassInitializeShouldThrowTestFailedExceptionWithInconclusiveOnAs exception.Should().NotBeNull(); exception.Outcome.Should().Be(UnitTestOutcome.Inconclusive); - exception.Message.Should().Be("Class Initialization method Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests+DummyTestClass.ClassInitializeMethod threw exception. Microsoft.VisualStudio.TestTools.UnitTesting.AssertInconclusiveException: Assert.Inconclusive failed. Test Inconclusive."); + exception.Message.Should().Be("Class Initialization method Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests+DummyTestClass.ClassInitializeMethod threw exception. Microsoft.VisualStudio.TestTools.UnitTesting.AssertInconclusiveException: Assert.Inconclusive. Test Inconclusive."); exception.StackTraceInformation!.ErrorStackTrace.Contains( "Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests.DummyTestClass.ClassInitializeMethod", StringComparison.Ordinal).Should().BeTrue(); exception.InnerException.Should().BeOfType(); @@ -481,7 +481,7 @@ public async Task RunClassCleanupShouldReturnAssertFailureExceptionDetails() // Assert classCleanupException.Should().NotBeNull(); classCleanupException.Message.StartsWith("Class Cleanup method DummyTestClass.ClassCleanupMethod failed.", StringComparison.Ordinal).Should().BeTrue(); - classCleanupException.Message.Contains("Error Message: Assert.Fail failed. Test Failure.").Should().BeTrue(); + classCleanupException.Message.Contains($"Error Message: Assertion failed.{Environment.NewLine}Test Failure.").Should().BeTrue(); classCleanupException.Message.Should().Contain( $"{typeof(TestClassInfoTests).FullName}.DummyTestClass.ClassCleanupMethod", $"Value: {classCleanupException.Message}"); @@ -502,7 +502,7 @@ public async Task RunClassCleanupShouldReturnAssertInconclusiveExceptionDetails( // Assert classCleanupException.Should().NotBeNull(); classCleanupException.Message.StartsWith("Class Cleanup method DummyTestClass.ClassCleanupMethod failed.", StringComparison.Ordinal).Should().BeTrue(); - classCleanupException.Message.Contains("Error Message: Assert.Inconclusive failed. Test Inconclusive.").Should().BeTrue(); + classCleanupException.Message.Contains("Error Message: Assert.Inconclusive. Test Inconclusive.").Should().BeTrue(); classCleanupException.Message.Should().Contain( $"{typeof(TestClassInfoTests).FullName}.DummyTestClass.ClassCleanupMethod", $"Value: {classCleanupException.Message}"); diff --git a/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestExecutionManagerTests.cs b/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestExecutionManagerTests.cs index e9ead72c13..59608bc623 100644 --- a/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestExecutionManagerTests.cs +++ b/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestExecutionManagerTests.cs @@ -159,7 +159,7 @@ public async Task RunTestsForMultipleTestShouldSendMultipleResults() List expectedTestCaseStartList = ["PassingTest", "FailingTest"]; List expectedTestCaseEndList = ["PassingTest:Passed", "FailingTest:Failed"]; - List expectedResultList = ["PassingTest Passed", "FailingTest Failed\r\n Message: Assert.Fail failed."]; + List expectedResultList = ["PassingTest Passed", "FailingTest Failed\r\n Message: Assertion failed."]; expectedTestCaseStartList.SequenceEqual(_frameworkHandle.TestCaseStartList).Should().BeTrue(); expectedTestCaseEndList.SequenceEqual(_frameworkHandle.TestCaseEndList).Should().BeTrue(); diff --git a/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestMethodInfoTests.cs b/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestMethodInfoTests.cs index e4ed2fa1a8..aa803a03b8 100644 --- a/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestMethodInfoTests.cs +++ b/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestMethodInfoTests.cs @@ -863,7 +863,7 @@ public async Task TestMethodInfoInvokeWhenTestThrowsAssertFailReturnsExpectedRes Resource.UTA_InitMethodThrows, typeof(DummyTestClass).FullName, _testClassInfo.TestInitializeMethod!.Name, - "Assert.Fail failed. dummyFailMessage"); + $"Assertion failed.{Environment.NewLine}dummyFailMessage"); var testMethodInfo = new TestMethodInfo(_methodInfo, _testClassInfo) { @@ -898,7 +898,7 @@ public async Task TestMethodInfoInvokeWhenTestThrowsAssertInconclusiveReturnsExp Resource.UTA_InitMethodThrows, typeof(DummyTestClass).FullName, _testClassInfo.TestInitializeMethod!.Name, - "Assert.Inconclusive failed. dummyFailMessage"); + "Assert.Inconclusive. dummyFailMessage"); var testMethodInfo = new TestMethodInfo(_methodInfo, _testClassInfo) { @@ -942,7 +942,7 @@ public async Task TestMethodInfoInvokeWhenConstructorThrowsAssertInconclusiveRet var exception = result.TestFailureException as TestFailedException; exception.Should().NotBeNull(); - exception.Message.Should().Be("Assert.Inconclusive failed. dummyInconclusiveMessage"); + exception.Message.Should().Be("Assert.Inconclusive. dummyInconclusiveMessage"); exception.Outcome.Should().Be(UnitTestOutcome.Inconclusive); exception.InnerException.Should().BeOfType(); #if DEBUG @@ -1110,7 +1110,7 @@ public async Task TestMethodInfoInvokeWhenTestCleanupThrowsAssertInconclusiveRet Resource.UTA_CleanupMethodThrows, typeof(DummyTestClass).FullName, _testClassInfo.TestCleanupMethod.Name, - "Microsoft.VisualStudio.TestTools.UnitTesting.AssertInconclusiveException: Assert.Inconclusive failed. Test inconclusive"); + "Microsoft.VisualStudio.TestTools.UnitTesting.AssertInconclusiveException: Assert.Inconclusive. Test inconclusive"); TestResult result = await _testMethodInfo.InvokeAsync(null); @@ -1137,7 +1137,7 @@ public async Task TestMethodInfoInvokeWhenTestCleanupThrowsAssertFailedReturnsEx Resource.UTA_CleanupMethodThrows, typeof(DummyTestClass).FullName, _testClassInfo.TestCleanupMethod!.Name, - "Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException: Assert.Fail failed. Test failed"); + $"Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException: Assertion failed.{Environment.NewLine}Test failed"); TestResult result = await _testMethodInfo.InvokeAsync(null); diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.FailInconclusive.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.FailInconclusive.cs new file mode 100644 index 0000000000..58e8380175 --- /dev/null +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.FailInconclusive.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using AwesomeAssertions; + +namespace Microsoft.VisualStudio.TestPlatform.TestFramework.UnitTests; + +public partial class AssertTests +{ + public void FailWithoutMessageShouldUseStructuredPrefixOnly() + { + Action action = () => Assert.Fail(); + action.Should().Throw() + .WithMessage("Assertion failed."); + } + + public void FailWithMessageShouldPlaceUserMessageOnOwnLine() + { + Action action = () => Assert.Fail("custom reason"); + action.Should().Throw() + .WithMessage( + """ + Assertion failed. + custom reason + """); + } + + public void FailWithEmptyMessageShouldNotAddBlankLine() + { + Action action = () => Assert.Fail(string.Empty); + action.Should().Throw() + .WithMessage("Assertion failed."); + } + + public void InconclusiveWithoutMessageShouldUseInconclusivePrefix() + { + Action action = () => Assert.Inconclusive(); + action.Should().Throw() + .WithMessage("Assert.Inconclusive."); + } + + public void InconclusiveWithMessageShouldAppendUserMessage() + { + Action action = () => Assert.Inconclusive("db unavailable"); + action.Should().Throw() + .WithMessage("Assert.Inconclusive. db unavailable"); + } +} diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.InconclusiveTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.InconclusiveTests.cs index d0b8d8fcc7..f580a72679 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.InconclusiveTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.InconclusiveTests.cs @@ -12,6 +12,6 @@ public void InconclusiveDoesNotThrowWhenMessageContainsInvalidStringFormatCompos { Action action = () => Assert.Inconclusive("{"); action.Should().Throw() - .And.Message.Should().Contain("Assert.Inconclusive failed. {"); + .And.Message.Should().Contain("Assert.Inconclusive. {"); } } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.ScopeTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.ScopeTests.cs index ab29d158f6..1b6e41b70f 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.ScopeTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.ScopeTests.cs @@ -134,7 +134,11 @@ public void Scope_AssertFail_IsHardFailure() // Assert.Fail is a hard assertion — it throws immediately, even within a scope. action.Should().Throw() - .WithMessage("Assert.Fail failed. first failure"); + .WithMessage( + """ + Assertion failed. + first failure + """); } public void Scope_AssertIsNotNull_IsSoftFailure()