forked from microsoft/testfx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMSTestExecutor.cs
73 lines (59 loc) · 2.71 KB
/
MSTestExecutor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
namespace Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter;
/// <summary>
/// Contains the execution logic for this adapter.
/// </summary>
[ExtensionUri(Constants.ExecutorUriString)]
public class MSTestExecutor : ITestExecutor
{
/// <summary>
/// Token for canceling the test run.
/// </summary>
private TestRunCancellationToken? _cancellationToken;
/// <summary>
/// Initializes a new instance of the <see cref="MSTestExecutor"/> class.
/// </summary>
public MSTestExecutor()
{
TestExecutionManager = new TestExecutionManager();
}
/// <summary>
/// Gets or sets the ms test execution manager.
/// </summary>
public TestExecutionManager TestExecutionManager { get; protected set; }
public void RunTests(IEnumerable<TestCase>? tests, IRunContext? runContext, IFrameworkHandle? frameworkHandle)
{
PlatformServiceProvider.Instance.AdapterTraceLogger.LogInfo("MSTestExecutor.RunTests: Running tests from testcases.");
ValidateArg.NotNull(frameworkHandle, "frameworkHandle");
ValidateArg.NotNullOrEmpty(tests, "tests");
if (!MSTestDiscovererHelpers.InitializeDiscovery(from test in tests select test.Source, runContext, frameworkHandle, false))
{
return;
}
_cancellationToken = new TestRunCancellationToken();
TestExecutionManager.RunTests(tests, runContext, frameworkHandle, _cancellationToken);
_cancellationToken = null;
}
public void RunTests(IEnumerable<string>? sources, IRunContext? runContext, IFrameworkHandle? frameworkHandle)
{
PlatformServiceProvider.Instance.AdapterTraceLogger.LogInfo("MSTestExecutor.RunTests: Running tests from sources.");
ValidateArg.NotNull(frameworkHandle, "frameworkHandle");
ValidateArg.NotNullOrEmpty(sources, "sources");
if (!MSTestDiscovererHelpers.InitializeDiscovery(sources, runContext, frameworkHandle, true))
{
return;
}
sources = PlatformServiceProvider.Instance.TestSource.GetTestSources(sources);
_cancellationToken = new TestRunCancellationToken();
TestExecutionManager.RunTests(sources, runContext, frameworkHandle, _cancellationToken);
_cancellationToken = null;
}
public void Cancel()
=> _cancellationToken?.Cancel();
}