Skip to content
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

Add support for testconfig.json entries in MSTest #3872

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 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
6 changes: 6 additions & 0 deletions src/Adapter/MSTest.TestAdapter/MSTestSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Xml;
using System.Xml.Linq;

using Microsoft.Testing.Platform.Configurations;
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
Expand Down Expand Up @@ -265,6 +266,11 @@ public static void PopulateSettings(MSTestSettings settings)
internal static void PopulateSettings(IDiscoveryContext? context, IMessageLogger? logger)
engyebrahim marked this conversation as resolved.
Show resolved Hide resolved
{
RunConfigurationSettings = RunConfigurationSettings.PopulateSettings(context);
IConfiguration? testConfig = MSTestDiscoverer.Configuration ?? MSTestExecutor.Configuration;
if (testConfig != null && context?.RunSettings == null)
{
// throw;
}

if (context?.RunSettings == null || StringEx.IsNullOrEmpty(context.RunSettings.SettingsXml))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,24 @@
using Microsoft.Testing.Extensions.VSTestBridge;
using Microsoft.Testing.Extensions.VSTestBridge.Requests;
using Microsoft.Testing.Platform.Capabilities.TestFramework;
using Microsoft.Testing.Platform.Configurations;
using Microsoft.Testing.Platform.Messages;
using Microsoft.Testing.Platform.Services;
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter;

namespace Microsoft.VisualStudio.TestTools.UnitTesting;

internal sealed class MSTestBridgedTestFramework : SynchronizedSingleSessionVSTestBridgedTestFramework
{
private readonly IConfiguration? _configration;

public MSTestBridgedTestFramework(MSTestExtension mstestExtension, Func<IEnumerable<Assembly>> getTestAssemblies,
IServiceProvider serviceProvider, ITestFrameworkCapabilities capabilities)
: base(mstestExtension, getTestAssemblies, serviceProvider, capabilities)
{
// check if it have mstest settings
IConfiguration config = serviceProvider.GetConfiguration();
_configration = config["mstest"] is null ? null : config;
}

/// <inheritdoc />
Expand All @@ -31,7 +38,7 @@ protected override Task SynchronizedDiscoverTestsAsync(VSTestDiscoverTestExecuti
Debugger.Launch();
}

new MSTestDiscoverer().DiscoverTests(request.AssemblyPaths, request.DiscoveryContext, request.MessageLogger, request.DiscoverySink);
MSTestDiscoverer.DiscoverTests(request.AssemblyPaths, request.DiscoveryContext, request.MessageLogger, request.DiscoverySink, _configration);
return Task.CompletedTask;
}

Expand All @@ -49,11 +56,11 @@ protected override Task SynchronizedRunTestsAsync(VSTestRunTestExecutionRequest

if (request.VSTestFilter.TestCases is { } testCases)
{
testExecutor.RunTests(testCases, request.RunContext, request.FrameworkHandle);
testExecutor.RunTests(testCases, request.RunContext, request.FrameworkHandle, _configration);
}
else
{
testExecutor.RunTests(request.AssemblyPaths, request.RunContext, request.FrameworkHandle);
testExecutor.RunTests(request.AssemblyPaths, request.RunContext, request.FrameworkHandle, _configration);
}

return Task.CompletedTask;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.Testing.Platform.Configurations;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
Expand All @@ -17,6 +18,8 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter;
[FileExtension(".exe")]
public class MSTestDiscoverer : ITestDiscoverer
{
internal static IConfiguration? Configuration { get; private set; }
engyebrahim marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Discovers the tests available from the provided source. Not supported for .xap source.
/// </summary>
Expand All @@ -26,12 +29,15 @@ public class MSTestDiscoverer : ITestDiscoverer
/// <param name="discoverySink">Used to send testcases and discovery related events back to Discoverer manager.</param>
[System.Security.SecurityCritical]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0", Justification = "Discovery context can be null.")]
public void DiscoverTests(IEnumerable<string> sources, IDiscoveryContext discoveryContext, IMessageLogger logger, ITestCaseDiscoverySink discoverySink)
public void DiscoverTests(IEnumerable<string> sources, IDiscoveryContext discoveryContext, IMessageLogger logger, ITestCaseDiscoverySink discoverySink) => MSTestDiscoverer.DiscoverTests(sources, discoveryContext, logger, discoverySink, null);

internal static void DiscoverTests(IEnumerable<string> sources, IDiscoveryContext discoveryContext, IMessageLogger logger, ITestCaseDiscoverySink discoverySink, IConfiguration? configuration)
{
ValidateArg.NotNull(sources, "sources");
ValidateArg.NotNull(logger, "logger");
ValidateArg.NotNull(discoverySink, "discoverySink");

Configuration = configuration;
engyebrahim marked this conversation as resolved.
Show resolved Hide resolved
if (MSTestDiscovererHelpers.InitializeDiscovery(sources, discoveryContext, logger))
{
new UnitTestDiscoverer().DiscoverTests(sources, logger, discoverySink, discoveryContext);
Expand Down
14 changes: 11 additions & 3 deletions src/Adapter/MSTest.TestAdapter/VSTestAdapter/MSTestExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Runtime.InteropServices;

using Microsoft.Testing.Platform.Configurations;
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
Expand All @@ -16,6 +17,8 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter;
[ExtensionUri(Constants.ExecutorUriString)]
public class MSTestExecutor : ITestExecutor
{
internal static IConfiguration? Configuration { get; private set; }

private readonly CancellationToken _cancellationToken;

/// <summary>
Expand Down Expand Up @@ -43,12 +46,17 @@ internal MSTestExecutor(CancellationToken cancellationToken)
/// </summary>
public TestExecutionManager TestExecutionManager { get; protected set; }

public void RunTests(IEnumerable<TestCase>? tests, IRunContext? runContext, IFrameworkHandle? frameworkHandle)
public void RunTests(IEnumerable<TestCase>? tests, IRunContext? runContext, IFrameworkHandle? frameworkHandle) => RunTests(tests, runContext, frameworkHandle, null);

public void RunTests(IEnumerable<string>? sources, IRunContext? runContext, IFrameworkHandle? frameworkHandle) => RunTests(sources, runContext, frameworkHandle, null);

internal void RunTests(IEnumerable<TestCase>? tests, IRunContext? runContext, IFrameworkHandle? frameworkHandle, IConfiguration? configuration)
{
PlatformServiceProvider.Instance.AdapterTraceLogger.LogInfo("MSTestExecutor.RunTests: Running tests from testcases.");
ValidateArg.NotNull(frameworkHandle, "frameworkHandle");
ValidateArg.NotNullOrEmpty(tests, "tests");

Configuration = configuration;
if (!MSTestDiscovererHelpers.InitializeDiscovery(from test in tests select test.Source, runContext, frameworkHandle))
{
return;
Expand All @@ -57,12 +65,12 @@ public void RunTests(IEnumerable<TestCase>? tests, IRunContext? runContext, IFra
RunTestsFromRightContext(frameworkHandle, testRunToken => TestExecutionManager.RunTests(tests, runContext, frameworkHandle, testRunToken));
}

public void RunTests(IEnumerable<string>? sources, IRunContext? runContext, IFrameworkHandle? frameworkHandle)
internal void RunTests(IEnumerable<string>? sources, IRunContext? runContext, IFrameworkHandle? frameworkHandle, IConfiguration? configuration)
{
PlatformServiceProvider.Instance.AdapterTraceLogger.LogInfo("MSTestExecutor.RunTests: Running tests from sources.");
ValidateArg.NotNull(frameworkHandle, "frameworkHandle");
ValidateArg.NotNullOrEmpty(sources, "sources");

Configuration = configuration;
if (!MSTestDiscovererHelpers.InitializeDiscovery(sources, runContext, frameworkHandle))
{
return;
Expand Down