Skip to content

VSTestBridge+MSTest: Use TestMethodIdentifierProperty and stop sending VSTest-specifics #5409

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 24 commits into from
Apr 25, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#if !WINDOWS_UWP
using Microsoft.Testing.Extensions.VSTestBridge.Capabilities;
using Microsoft.Testing.Extensions.TrxReport.Abstractions;
using Microsoft.Testing.Extensions.VSTestBridge.Helpers;
using Microsoft.Testing.Platform.Builder;
using Microsoft.Testing.Platform.Capabilities.TestFramework;
Expand All @@ -17,6 +17,17 @@ namespace Microsoft.VisualStudio.TestTools.UnitTesting;
[SuppressMessage("ApiDesign", "RS0030:Do not use banned APIs", Justification = "We can use MTP from this folder")]
public static class TestApplicationBuilderExtensions
{
// NOTE: We intentionally use this class and not VSTestBridgeExtensionBaseCapabilities because
// we don't want MSTest to use vstestProvider capability
private sealed class MSTestCapabilities : ITrxReportCapability
{
bool ITrxReportCapability.IsSupported { get; } = true;

void ITrxReportCapability.Enable()
{
}
}

/// <summary>
/// Register MSTest as the test framework and register the necessary services.
/// </summary>
Expand All @@ -34,7 +45,7 @@ public static void AddMSTest(this ITestApplicationBuilder testApplicationBuilder
testApplicationBuilder.AddRunSettingsEnvironmentVariableProvider(extension);
testApplicationBuilder.RegisterTestFramework(
serviceProvider => new TestFrameworkCapabilities(
new VSTestBridgeExtensionBaseCapabilities(),
new MSTestCapabilities(),
#pragma warning disable TPEXP // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
new MSTestBannerCapability(serviceProvider.GetRequiredService<IPlatformInformation>()),
MSTestGracefulStopTestExecutionCapability.Instance),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ namespace Microsoft.Testing.Extensions.VSTestBridge.Capabilities;
/// <summary>
/// The VSTest bridged test framework capabilities.
/// </summary>
// NOTE: MSTest no longer uses this, as we don't want to use the vstestProvider.
// Only NUnit and Expecto use this.
// https://github.com/nunit/nunit3-vs-adapter/blob/3d0f824243aaaeb85621d3c7dddc92e7a7c45097/src/NUnitTestAdapter/TestingPlatformAdapter/TestApplicationBuilderExtensions.cs#L20
// https://github.com/YoloDev/YoloDev.Expecto.TestSdk/blob/0d1a3eadd65b605f61bb01d302f28382be76b8ac/src/YoloDev.Expecto.TestSdk/TestApplicationHelpers.fs#L16
public sealed class VSTestBridgeExtensionBaseCapabilities : ITrxReportCapability, IVSTestFlattenedTestNodesReportCapability, INamedFeatureCapability
{
private const string VSTestProviderSupport = "vstestProvider";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" />
<PackageReference Include="Microsoft.TestPlatform.AdapterUtilities" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#pragma warning disable TPEXP // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.

using Microsoft.Testing.Extensions.VSTestBridge.Helpers;
using Microsoft.Testing.Platform.Capabilities.TestFramework;
using Microsoft.Testing.Platform.CommandLine;
using Microsoft.Testing.Platform.Extensions.Messages;
using Microsoft.Testing.Platform.Logging;
using Microsoft.Testing.Platform.Messages;
Expand All @@ -30,15 +32,26 @@ internal sealed class FrameworkHandlerAdapter : IFrameworkHandle
private readonly IMessageBus _messageBus;
private readonly VSTestBridgedTestFrameworkBase _adapterExtensionBase;
private readonly TestSessionContext _session;
private readonly IClientInfo _clientInfo;
private readonly CancellationToken _cancellationToken;
private readonly bool _isTrxEnabled;
private readonly MessageLoggerAdapter _comboMessageLogger;
private readonly string _testAssemblyPath;

public FrameworkHandlerAdapter(VSTestBridgedTestFrameworkBase adapterExtensionBase, TestSessionContext session, IClientInfo clientInfo, string[] testAssemblyPaths,
ITestApplicationModuleInfo testApplicationModuleInfo, ILoggerFactory loggerFactory, IMessageBus messageBus, IOutputDevice outputDevice,
bool isTrxEnabled, CancellationToken cancellationToken, IFrameworkHandle? frameworkHandle = null)
private readonly INamedFeatureCapability? _namedFeatureCapability;
private readonly ICommandLineOptions _commandLineOptions;

public FrameworkHandlerAdapter(
VSTestBridgedTestFrameworkBase adapterExtensionBase,
TestSessionContext session,
string[] testAssemblyPaths,
ITestApplicationModuleInfo testApplicationModuleInfo,
INamedFeatureCapability? namedFeatureCapability,
ICommandLineOptions commandLineOptions,
IMessageBus messageBus,
IOutputDevice outputDevice,
ILoggerFactory loggerFactory,
bool isTrxEnabled,
CancellationToken cancellationToken,
IFrameworkHandle? frameworkHandle = null)
{
if (testAssemblyPaths.Length == 0)
{
Expand All @@ -58,12 +71,13 @@ public FrameworkHandlerAdapter(VSTestBridgedTestFrameworkBase adapterExtensionBa
_testAssemblyPath = testAssemblyPaths[0];
}

_namedFeatureCapability = namedFeatureCapability;
_commandLineOptions = commandLineOptions;
_frameworkHandle = frameworkHandle;
_logger = loggerFactory.CreateLogger<FrameworkHandlerAdapter>();
_messageBus = messageBus;
_adapterExtensionBase = adapterExtensionBase;
_session = session;
_clientInfo = clientInfo;
_cancellationToken = cancellationToken;
_isTrxEnabled = isTrxEnabled;
_comboMessageLogger = new MessageLoggerAdapter(loggerFactory, outputDevice, adapterExtensionBase, frameworkHandle);
Expand Down Expand Up @@ -126,7 +140,7 @@ public void RecordResult(TestResult testResult)
_frameworkHandle?.RecordResult(testResult);

// Publish node state change to Microsoft Testing Platform
var testNode = testResult.ToTestNode(_isTrxEnabled, _clientInfo);
var testNode = testResult.ToTestNode(_isTrxEnabled, _namedFeatureCapability, _commandLineOptions);

var testNodeChange = new TestNodeUpdateMessage(_session.SessionUid, testNode);
_messageBus.PublishAsync(_adapterExtensionBase, testNodeChange).Await();
Expand All @@ -145,7 +159,7 @@ public void RecordStart(TestCase testCase)
_frameworkHandle?.RecordStart(testCase);

// Publish node state change to Microsoft Testing Platform
var testNode = testCase.ToTestNode(_isTrxEnabled, _clientInfo);
var testNode = testCase.ToTestNode(_isTrxEnabled, _namedFeatureCapability, _commandLineOptions);
testNode.Properties.Add(InProgressTestNodeStateProperty.CachedInstance);
var testNodeChange = new TestNodeUpdateMessage(_session.SessionUid, testNode);

Expand Down
Loading
Loading