diff --git a/src/Platform/Microsoft.Testing.Extensions.TrxReport/TrxReportEngine.cs b/src/Platform/Microsoft.Testing.Extensions.TrxReport/TrxReportEngine.cs index 5ea30af31c..260b0f8585 100644 --- a/src/Platform/Microsoft.Testing.Extensions.TrxReport/TrxReportEngine.cs +++ b/src/Platform/Microsoft.Testing.Extensions.TrxReport/TrxReportEngine.cs @@ -412,7 +412,8 @@ private SummaryCounts AddResults(TestNodeUpdateMessage[] testNodeUpdateMessages, // NOTE: In VSTest, MSTestDiscoverer.TmiTestId property is preferred if present. string id = guid.ToString(); - string displayName = RemoveInvalidXmlChar(testNode.DisplayName)!; + string testNodeDisplayName = RemoveInvalidXmlChar(testNode.DisplayName)!; + string testResultDisplayName = RemoveInvalidXmlChar(nodeMessage.DisplayName)!; string executionId = Guid.NewGuid().ToString(); // Results @@ -420,7 +421,7 @@ private SummaryCounts AddResults(TestNodeUpdateMessage[] testNodeUpdateMessages, "UnitTestResult", new XAttribute("executionId", executionId), new XAttribute("testId", id), - new XAttribute("testName", displayName), + new XAttribute("testName", testResultDisplayName), new XAttribute("computerName", _environment.MachineName)); TimingProperty? timing = testNode.Properties.SingleOrDefault(); @@ -563,7 +564,7 @@ private SummaryCounts AddResults(TestNodeUpdateMessage[] testNodeUpdateMessages, // Add the test method to the test definitions if it's not already there if (uniqueTestDefinitionTestIds.Add(id)) { - XElement unitTest = CreateUnitTestElementForTestDefinition(displayName, testAppModule, id, testNode, executionId); + XElement unitTest = CreateUnitTestElementForTestDefinition(testNodeDisplayName, testAppModule, id, testNode, executionId); var testMethod = new XElement( "TestMethod", @@ -574,13 +575,13 @@ private SummaryCounts AddResults(TestNodeUpdateMessage[] testNodeUpdateMessages, (string className, string? testMethodName) = GetClassAndMethodName(testNode); testMethod.SetAttributeValue("className", className); - // NOTE: Historically, MTP used to always use displayName here. - // While VSTest never uses displayName. - // The use of displayName here is very wrong. + // NOTE: Historically, MTP used to always use testNodeDisplayName here. + // While VSTest never uses testNodeDisplayName. + // The use of testNodeDisplayName here is very wrong. // We keep it as a fallback if we cannot determine the testMethodName (when TestMethodIdentifierProperty isn't present). // This will most likely be hit for NUnit. // However, this is very wrong and we probably should fail if TestMethodIdentifierProperty isn't present. - testMethod.SetAttributeValue("name", testMethodName ?? displayName); + testMethod.SetAttributeValue("name", testMethodName ?? testNodeDisplayName); unitTest.Add(testMethod); diff --git a/src/Platform/Microsoft.Testing.Extensions.VSTestBridge/ObjectModel/FrameworkHandlerAdapter.cs b/src/Platform/Microsoft.Testing.Extensions.VSTestBridge/ObjectModel/FrameworkHandlerAdapter.cs index ec0660d7cf..ace2fdda0d 100644 --- a/src/Platform/Microsoft.Testing.Extensions.VSTestBridge/ObjectModel/FrameworkHandlerAdapter.cs +++ b/src/Platform/Microsoft.Testing.Extensions.VSTestBridge/ObjectModel/FrameworkHandlerAdapter.cs @@ -135,7 +135,7 @@ public void RecordResult(TestResult testResult) // Publish node state change to Microsoft Testing Platform var testNode = testResult.ToTestNode(_isTrxEnabled, _adapterExtensionBase.UseFullyQualifiedNameAsTestNodeUid, _adapterExtensionBase.AddAdditionalProperties, _namedFeatureCapability, _commandLineOptions, _clientInfo); - var testNodeChange = new TestNodeUpdateMessage(_session.SessionUid, testNode); + var testNodeChange = new TestNodeUpdateMessage(_session.SessionUid, testResult.DisplayName ?? testNode.DisplayName, testNode); _messageBus.PublishAsync(_adapterExtensionBase, testNodeChange).Await(); } diff --git a/src/Platform/Microsoft.Testing.Extensions.VSTestBridge/ObjectModel/ObjectModelConverters.cs b/src/Platform/Microsoft.Testing.Extensions.VSTestBridge/ObjectModel/ObjectModelConverters.cs index 8ddc5ca5a7..45f9878268 100644 --- a/src/Platform/Microsoft.Testing.Extensions.VSTestBridge/ObjectModel/ObjectModelConverters.cs +++ b/src/Platform/Microsoft.Testing.Extensions.VSTestBridge/ObjectModel/ObjectModelConverters.cs @@ -33,15 +33,14 @@ public static TestNode ToTestNode( Action addAdditionalProperties, INamedFeatureCapability? namedFeatureCapability, ICommandLineOptions commandLineOptions, - IClientInfo clientInfo, - string? displayNameFromTestResult = null) + IClientInfo clientInfo) { string testNodeUid = useFullyQualifiedNameAsUid ? testCase.FullyQualifiedName : testCase.Id.ToString(); TestNode testNode = new() { Uid = new TestNodeUid(testNodeUid), - DisplayName = displayNameFromTestResult ?? testCase.DisplayName ?? testCase.FullyQualifiedName, + DisplayName = testCase.DisplayName ?? testCase.FullyQualifiedName, }; CopyCategoryAndTraits(testCase, testNode, isTrxEnabled); @@ -132,7 +131,7 @@ public static TestNode ToTestNode( ICommandLineOptions commandLineOptions, IClientInfo clientInfo) { - var testNode = testResult.TestCase.ToTestNode(isTrxEnabled, useFullyQualifiedNameAsUid, addAdditionalProperties, namedFeatureCapability, commandLineOptions, clientInfo, testResult.DisplayName); + var testNode = testResult.TestCase.ToTestNode(isTrxEnabled, useFullyQualifiedNameAsUid, addAdditionalProperties, namedFeatureCapability, commandLineOptions, clientInfo); CopyCategoryAndTraits(testResult, testNode, isTrxEnabled); diff --git a/src/Platform/Microsoft.Testing.Platform/Messages/TestNodeUpdateMessage.cs b/src/Platform/Microsoft.Testing.Platform/Messages/TestNodeUpdateMessage.cs index 5cfe5b8b05..91f6d12b72 100644 --- a/src/Platform/Microsoft.Testing.Platform/Messages/TestNodeUpdateMessage.cs +++ b/src/Platform/Microsoft.Testing.Platform/Messages/TestNodeUpdateMessage.cs @@ -10,10 +10,24 @@ namespace Microsoft.Testing.Platform.Extensions.Messages; /// /// The session UID. /// The test node. +/// The display name for the test update. /// The test node parent UID. -public sealed class TestNodeUpdateMessage(SessionUid sessionUid, TestNode testNode, TestNodeUid? parentTestNodeUid = null) - : DataWithSessionUid("TestNode update", "This data is used to report a TestNode state change.", sessionUid) +#pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters +public sealed class TestNodeUpdateMessage(SessionUid sessionUid, string displayName, TestNode testNode, TestNodeUid? parentTestNodeUid = null) : +#pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters + DataWithSessionUid(displayName, "This data is used to report a TestNode state change.", sessionUid) { + /// + /// Initializes a new instance of the class. + /// + /// The session UID. + /// The test node. + /// The test node parent UID. + public TestNodeUpdateMessage(SessionUid sessionUid, TestNode testNode, TestNodeUid? parentTestNodeUid = null) + : this(sessionUid, testNode.DisplayName, testNode, parentTestNodeUid) + { + } + /// /// Gets the test node. /// diff --git a/src/Platform/Microsoft.Testing.Platform/PublicAPI/PublicAPI.Unshipped.txt b/src/Platform/Microsoft.Testing.Platform/PublicAPI/PublicAPI.Unshipped.txt index 05eaa9f07e..89402ff8f1 100644 --- a/src/Platform/Microsoft.Testing.Platform/PublicAPI/PublicAPI.Unshipped.txt +++ b/src/Platform/Microsoft.Testing.Platform/PublicAPI/PublicAPI.Unshipped.txt @@ -2,6 +2,7 @@ *REMOVED*Microsoft.Testing.Platform.Extensions.TestHost.ITestHostApplicationLifetime.AfterRunAsync(int exitCode, System.Threading.CancellationToken cancellation) -> System.Threading.Tasks.Task! *REMOVED*Microsoft.Testing.Platform.Extensions.TestHostControllers.ITestHostProcessLifetimeHandler.OnTestHostProcessExitedAsync(Microsoft.Testing.Platform.Extensions.TestHostControllers.ITestHostProcessInformation! testHostProcessInformation, System.Threading.CancellationToken cancellation) -> System.Threading.Tasks.Task! *REMOVED*Microsoft.Testing.Platform.Extensions.TestHostControllers.ITestHostProcessLifetimeHandler.OnTestHostProcessStartedAsync(Microsoft.Testing.Platform.Extensions.TestHostControllers.ITestHostProcessInformation! testHostProcessInformation, System.Threading.CancellationToken cancellation) -> System.Threading.Tasks.Task! +Microsoft.Testing.Platform.Extensions.Messages.TestNodeUpdateMessage.TestNodeUpdateMessage(Microsoft.Testing.Platform.TestHost.SessionUid sessionUid, string! displayName, Microsoft.Testing.Platform.Extensions.Messages.TestNode! testNode, Microsoft.Testing.Platform.Extensions.Messages.TestNodeUid? parentTestNodeUid = null) -> void Microsoft.Testing.Platform.Extensions.TestHost.ITestHostApplicationLifetime.AfterRunAsync(int exitCode, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task! Microsoft.Testing.Platform.Extensions.TestHostControllers.ITestHostProcessLifetimeHandler.OnTestHostProcessExitedAsync(Microsoft.Testing.Platform.Extensions.TestHostControllers.ITestHostProcessInformation! testHostProcessInformation, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task! Microsoft.Testing.Platform.Extensions.TestHostControllers.ITestHostProcessLifetimeHandler.OnTestHostProcessStartedAsync(Microsoft.Testing.Platform.Extensions.TestHostControllers.ITestHostProcessInformation! testHostProcessInformation, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task!