-
Notifications
You must be signed in to change notification settings - Fork 558
/
Copy pathCosmosTestExecutor.cs
67 lines (51 loc) · 2.27 KB
/
CosmosTestExecutor.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
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Threading;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
using Cosmos.TestRunner.Core;
namespace Cosmos.TestRunner.TestAdapter
{
[ExtensionUri(ExecutorUri)]
public sealed class CosmosTestExecutor : ITestExecutor
{
public const string ExecutorUri = "executor://CosmosTestExecutor";
private CancellationTokenSource _cancellationTokenSource;
public void RunTests(
IEnumerable<TestCase> tests,
IRunContext runContext,
IFrameworkHandle frameworkHandle)
{
_cancellationTokenSource = new CancellationTokenSource();
foreach (var test in tests)
{
var configuration = new EngineConfiguration(new string[] { test.Source }, runContext);
var testEngine = new Engine(configuration);
var outputHandler = new TestAdapterOutputHandler(frameworkHandle);
testEngine.SetOutputHandler(outputHandler);
var testResult = new TestResult(test);
frameworkHandle.RecordStart(test);
var kernelTestResult = testEngine.Execute(_cancellationTokenSource.Token).KernelTestResults[0];
testResult.Outcome = kernelTestResult.Result ? TestOutcome.Passed : TestOutcome.Failed;
var messages = new Collection<TestResultMessage>();
foreach (var message in outputHandler.Messages)
{
messages.Add(new TestResultMessage(String.Empty, message));
}
frameworkHandle.RecordEnd(test, testResult.Outcome);
frameworkHandle.RecordResult(testResult);
}
}
public void RunTests(
IEnumerable<string> sources,
IRunContext runContext,
IFrameworkHandle frameworkHandle)
{
var discoverer = new CosmosTestDiscoverer();
var tests = discoverer.DiscoverTests(sources, runContext, null);
RunTests(tests, runContext, frameworkHandle);
}
public void Cancel() => _cancellationTokenSource.Cancel();
}
}