Skip to content
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
13 changes: 7 additions & 6 deletions src/Adapter/MSTest.TestAdapter/MSTest.TestAdapter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@

<!-- Curated package dependencies. PrivateAssets="none" so all assets (including build/buildTransitive
targets, e.g. from Microsoft.Testing.Platform.MSBuild) flow to consumers. -->
<ProjectReference Include="$(RepoRoot)src\Platform\Microsoft.Testing.Extensions.VSTestBridge\Microsoft.Testing.Extensions.VSTestBridge.csproj" Condition=" '$(TargetFramework)' != '$(UwpMinimum)' " PrivateAssets="none" />
<ProjectReference Include="$(RepoRoot)src\Platform\Microsoft.Testing.Extensions.TrxReport.Abstractions\Microsoft.Testing.Extensions.TrxReport.Abstractions.csproj" Condition=" '$(TargetFramework)' != '$(UwpMinimum)' " PrivateAssets="none" />
<ProjectReference Include="$(RepoRoot)src\Platform\Microsoft.Testing.Extensions.Telemetry\Microsoft.Testing.Extensions.Telemetry.csproj" Condition=" '$(TargetFramework)' != '$(UwpMinimum)' " PrivateAssets="none" />
<ProjectReference Include="$(RepoRoot)src\Platform\Microsoft.Testing.Platform.MSBuild\Microsoft.Testing.Platform.MSBuild.csproj" Condition=" '$(TargetFramework)' != '$(UwpMinimum)' " PrivateAssets="none" />
<!-- On Windows the package depends on MSTest.TestFramework, matching the historical MSTest.TestAdapter.nuspec.
The historical MSTest.TestAdapter.NonWindows.nuspec did NOT declare this dependency, so on non-Windows builds
Expand All @@ -83,11 +84,11 @@
<PackageReference Include="System.Threading.Tasks.Extensions" Condition=" '$(TargetFramework)' == '$(NetFrameworkMinimum)' OR '$(TargetFramework)' == '$(UwpMinimum)' " />
<PackageReference Include="System.Memory" Condition=" '$(TargetFramework)' == '$(NetFrameworkMinimum)' OR '$(TargetFramework)' == '$(UwpMinimum)' " />

<!-- The adapter's VSTest-facing code (VSTestAdapter\*, AdapterTestProperties) uses the VSTest object model
directly. On other TFMs it flows in transitively via Microsoft.Testing.Extensions.VSTestBridge, but that
reference is not added for UWP (see above), and PlatformServices no longer references the object model,
so it is referenced explicitly here for UWP. -->
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" Condition=" '$(TargetFramework)' == '$(UwpMinimum)' " />
<!-- The adapter's VSTest-facing code (VSTestAdapter\*, AdapterTestProperties) and the native Microsoft.Testing.Platform
integration (TestingPlatformAdapter\MSTestFilterContext) use the VSTest object model directly. It used to flow
in transitively via Microsoft.Testing.Extensions.VSTestBridge; now that the bridge reference is gone it is
referenced explicitly for every TFM. -->
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" />

<!-- The native Microsoft.Testing.Platform integration (TestingPlatformAdapter\MSTestFilterContext, guarded by
!WINDOWS_UWP) parses VSTest filter expressions via the Filter source package. It flows in transitively via
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.TestingPlatform
/// context adapters.
/// </summary>
/// <remarks>
/// This mirrors, for the MSTest native path, what <c>ContextAdapterBase</c> / <c>RunContextAdapter</c> /
/// <c>DiscoveryContextAdapter</c> do in <c>Microsoft.Testing.Extensions.VSTestBridge</c>. The filter-expression
/// parsing itself reuses the VSTest <c>Microsoft.TestPlatform.Filter.Source</c> package, exactly like the bridge.
/// This mirrors, for the MSTest native path, the former bridge context-adapter behavior
/// (<c>ContextAdapterBase</c> / <c>RunContextAdapter</c> / <c>DiscoveryContextAdapter</c>). The
/// filter-expression parsing itself reuses the VSTest <c>Microsoft.TestPlatform.Filter.Source</c> package.
/// </remarks>
[SuppressMessage("ApiDesign", "RS0030:Do not use banned APIs", Justification = "We can use MTP from this folder")]
internal abstract class MSTestFilterContextBase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,12 @@
namespace Microsoft.VisualStudio.TestTools.UnitTesting;

/// <summary>
/// A native Microsoft.Testing.Platform (MTP) test framework for MSTest. Unlike <see cref="MSTestBridgedTestFramework"/>
/// it does not derive from the VSTest bridge: it handles the MTP discovery/run requests directly, builds the run
/// context, filter and runsettings natively (see <see cref="MSTestRunContext"/> / <see cref="MSTestDiscoveryContext"/>
/// / <see cref="MSTestRunSettings"/>), and publishes test nodes through the native <see cref="MtpUnitTestElementSink"/>
/// / <see cref="MtpTestResultRecorder"/>. It reuses MSTest's existing <see cref="MSTestDiscoverer"/> /
/// <see cref="MSTestExecutor"/> engine.
/// A native Microsoft.Testing.Platform (MTP) test framework for MSTest. It does not derive from the VSTest bridge:
/// it handles the MTP discovery/run requests directly, builds the run context, filter and runsettings natively
/// (see <see cref="MSTestRunContext"/> / <see cref="MSTestDiscoveryContext"/> / <see cref="MSTestRunSettings"/>), and
/// publishes test nodes through the native <see cref="MtpUnitTestElementSink"/> / <see cref="MtpTestResultRecorder"/>.
/// It reuses MSTest's existing <see cref="MSTestDiscoverer"/> / <see cref="MSTestExecutor"/> engine.
/// </summary>
/// <remarks>
/// This is opt-in (behind <c>MSTEST_EXPERIMENTAL_NATIVE_MTP</c>) while the native path reaches full parity with the
/// bridge. It still relies on the bridge only for the shared command-line options (<c>--filter</c>, <c>--settings</c>,
/// <c>--test-parameter</c>) and the runsettings configuration/environment-variable providers; retiring those and the
/// bridge package reference is the final step of the migration.
/// </remarks>
[SuppressMessage("ApiDesign", "RS0030:Do not use banned APIs", Justification = "We can use MTP from this folder")]
[StackTraceHidden]
internal sealed class MSTestTestFramework : ITestFramework, IDataProducer, IDisposable
Expand All @@ -44,7 +37,7 @@ internal sealed class MSTestTestFramework : ITestFramework, IDataProducer, IDisp
private readonly Func<IEnumerable<Assembly>> _getTestAssemblies;
private readonly IServiceProvider _serviceProvider;
private readonly ITrxReportCapability? _trxReportCapability;
private readonly BridgedConfiguration _configuration;
private readonly PlatformServicesConfigurationAdapter _configuration;
private readonly ILoggerFactory _loggerFactory;
private readonly CountdownEvent _incomingRequestCounter = new(1);
private bool? _isTrxEnabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ namespace Microsoft.VisualStudio.TestTools.UnitTesting;
/// VSTest object model (<c>TestCase</c>/<c>TestResult</c>) or the VSTest bridge.
/// </summary>
/// <remarks>
/// This mirrors, field-for-field, the mapping that the bridge performs today in
/// This mirrors, field-for-field, the mapping that the VSTest bridge performed in
/// <c>ObjectModelConverters.ToTestNode</c> (combined with <c>UnitTestElementExtensions.ToTestCase</c>,
/// <c>TestResultExtensions.ToTestResult</c> and <c>MSTestBridgedTestFramework.AddAdditionalProperties</c>), so
/// <c>TestResultExtensions.ToTestResult</c> and the bridge's <c>AddAdditionalProperties</c>), so
/// switching MSTest to a native Microsoft.Testing.Platform integration produces identical <see cref="TestNode"/>s.
/// MSTest does not use the <c>vstestProvider</c> named-feature capability, so the VSTest provider properties the
/// bridge conditionally emits are intentionally not reproduced here.
Expand Down Expand Up @@ -133,7 +133,7 @@ private static void AddCategoriesAndTraits(TestNode testNode, UnitTestElement el
private static void AddTestMethodIdentifier(TestNode testNode, TestMethod testMethod)
{
// NOTE: ManagedMethodName, in case of MSTest, carries the parameter types, so we prefer it to display the
// parameter types in Test Explorer. This mirrors MSTestBridgedTestFramework.AddAdditionalProperties.
// parameter types in Test Explorer. This mirrors what the VSTest bridge did in AddAdditionalProperties.
if (!testMethod.HasManagedMethodAndTypeProperties)
{
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
namespace Microsoft.VisualStudio.TestTools.UnitTesting;

[SuppressMessage("ApiDesign", "RS0030:Do not use banned APIs", Justification = "We can use MTP from this folder")]
internal sealed class BridgedConfiguration : PlatformServicesConfiguration
internal sealed class PlatformServicesConfigurationAdapter : PlatformServicesConfiguration
{
private readonly IConfiguration _configuration;

public BridgedConfiguration(IConfiguration configuration)
public PlatformServicesConfigurationAdapter(IConfiguration configuration)
=> _configuration = configuration;

public string? this[string key] => _configuration[key];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#if !WINDOWS_UWP
using Microsoft.Testing.Extensions.TrxReport.Abstractions;
using Microsoft.Testing.Extensions.VSTestBridge.Capabilities;
using Microsoft.Testing.Platform.Builder;
using Microsoft.Testing.Platform.Capabilities.TestFramework;
using Microsoft.Testing.Platform.Helpers;
Expand All @@ -19,10 +18,9 @@ namespace Microsoft.VisualStudio.TestTools.UnitTesting;
public static class TestApplicationBuilderExtensions
{
// NOTE: We intentionally do not use the bridge's VSTestBridgeExtensionBaseCapabilities because we don't want
// MSTest to use the vstestProvider capability. This implements BOTH the bridge's TRX capability interface (read
// by MSTestBridgedTestFramework, the current default) and MSTest's native one (read by MSTestTestFramework), so
// both frameworks observe the same TRX enablement.
private sealed class MSTestCapabilities : IInternalVSTestBridgeTrxReportCapability, IMSTestTrxReportCapability
// MSTest to use the vstestProvider capability. This implements MSTest's native TRX capability, read by
// MSTestTestFramework.
private sealed class MSTestCapabilities : IMSTestTrxReportCapability
{
public bool IsTrxEnabled { get; private set; }

Expand Down Expand Up @@ -56,19 +54,13 @@ public static void AddMSTest(this ITestApplicationBuilder testApplicationBuilder
testApplicationBuilder.TestHostControllers.AddEnvironmentVariableProvider(serviceProvider
=> new MSTestRunSettingsEnvironmentVariableProvider(extension, serviceProvider.GetCommandLineOptions(), serviceProvider.GetFileSystem(), serviceProvider.GetEnvironment()));

// When the experimental native MTP integration is enabled, MSTest plugs into Microsoft.Testing.Platform
// directly (no VSTest bridge object model on the request path). Off by default, so shipping behavior is
// the bridged framework.
bool useNativeMtp = Environment.GetEnvironmentVariable("MSTEST_EXPERIMENTAL_NATIVE_MTP") is "1" or "true" or "True";

// MSTest plugs into Microsoft.Testing.Platform directly (no VSTest bridge object model on the request path).
testApplicationBuilder.RegisterTestFramework(
serviceProvider => new TestFrameworkCapabilities(
new MSTestCapabilities(),
new MSTestBannerCapability(serviceProvider.GetRequiredService<IPlatformInformation>()),
MSTestGracefulStopTestExecutionCapability.Instance),
(capabilities, serviceProvider) => useNativeMtp
? new MSTestTestFramework(extension, getTestAssemblies, serviceProvider, capabilities)
: new MSTestBridgedTestFramework(extension, getTestAssemblies, serviceProvider, capabilities));
(capabilities, serviceProvider) => new MSTestTestFramework(extension, getTestAssemblies, serviceProvider, capabilities));
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal sealed class MSTestDiscoverer : ITestDiscoverer

// The parameterless constructor is required by VSTest, which instantiates the
// discoverer via reflection. The internal constructor exists for tests and for the
// MTP bridge (MSTestBridgedTestFramework) which injects a telemetry sender.
// native Microsoft.Testing.Platform framework (MSTestTestFramework) which injects a telemetry sender.
public MSTestDiscoverer()
: this(new TestSourceHandler())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,8 @@ public async Task DiscoverTests_WithJsonOutput_ProducesValidJsonDocumentWithExpe
}

// Test1 should expose its TestMethodIdentifierProperty data, pinning every v1 schema field
// for that node from the outside. Note: MSTest's VSTestBridge currently leaves
// assemblyFullName and returnTypeFullName empty (TODO in MSTestBridgedTestFramework);
// assert presence only for those.
// for that node from the outside. MSTest currently leaves assemblyFullName and
// returnTypeFullName empty, so assert presence only for those.
bool foundTest1WithType = false;
for (int i = 0; i < tests.GetArrayLength(); i++)
{
Expand Down
Loading
Loading