TestRunnerApi.cs
2.87 KB
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
74
75
76
77
78
79
80
81
using System;
using System.Linq;
using System.Threading;
using UnityEngine;
using UnityEngine.TestRunner.TestLaunchers;
using UnityEngine.TestTools;
using UnityEngine.TestTools.NUnitExtensions;
namespace UnityEditor.TestTools.TestRunner.Api
{
internal class TestRunnerApi : ScriptableObject, ITestRunnerApi
{
public void Execute(ExecutionSettings executionSettings)
{
if (executionSettings == null)
{
throw new ArgumentException("Filter for execution is undefined.");
}
var launcherFactory = new TestLauncherFactory();
var data = TestRunData.instance;
data.executionSettings = executionSettings;
var testLauncher = launcherFactory.GetLauncher(executionSettings);
testLauncher.Run();
}
public void RegisterCallbacks<T>(T testCallbacks, int priority = 0) where T : ICallbacks
{
if (testCallbacks == null)
{
throw new ArgumentException("TestCallbacks for execution is undefined.");
}
CallbacksHolder.instance.Add(testCallbacks, priority);
}
public void UnregisterCallbacks<T>(T testCallbacks) where T : ICallbacks
{
if (testCallbacks == null)
{
throw new ArgumentException("TestCallbacks for execution is undefined.");
}
CallbacksHolder.instance.Remove(testCallbacks);
}
public void RetrieveTestList(ExecutionSettings executionSettings, Action<ITestAdaptor> callback)
{
if (executionSettings == null)
{
throw new ArgumentException("Filter for execution is undefined.");
}
if (callback == null)
{
throw new ArgumentException("Callback is undefined.");
}
var platform = ParseTestMode(executionSettings.filter.testMode);
var testAssemblyProvider = new EditorLoadedTestAssemblyProvider(new EditorCompilationInterfaceProxy(), new EditorAssembliesProxy());
var testAdaptorFactory = new TestAdaptorFactory();
var testListCache = new TestListCache(testAdaptorFactory, new RemoteTestResultDataFactory(), TestListCacheData.instance);
var testListProvider = new TestListProvider(testAssemblyProvider, new UnityTestAssemblyBuilder());
var cachedTestListProvider = new CachingTestListProvider(testListProvider, testListCache, testAdaptorFactory);
var job = new TestListJob(cachedTestListProvider, platform, callback);
job.Start();
}
private static TestPlatform ParseTestMode(TestMode testmode)
{
if (testmode == TestMode.EditMode)
{
return TestPlatform.EditMode;
}
return TestPlatform.PlayMode;
}
}
}