BuildTestTreeTask.cs
2.31 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
using System;
using System.Collections;
using System.Linq;
using UnityEditor.TestTools.TestRunner.Api;
using UnityEngine.TestRunner.NUnitExtensions;
using UnityEngine.TestTools;
using UnityEngine.TestTools.NUnitExtensions;
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks
{
internal class BuildTestTreeTask : TestTaskBase
{
private TestPlatform m_TestPlatform;
public BuildTestTreeTask(TestPlatform testPlatform)
{
m_TestPlatform = testPlatform;
}
internal IEditorLoadedTestAssemblyProvider m_testAssemblyProvider = new EditorLoadedTestAssemblyProvider(new EditorCompilationInterfaceProxy(), new EditorAssembliesProxy());
internal IAsyncTestAssemblyBuilder m_testAssemblyBuilder = new UnityTestAssemblyBuilder();
internal ICallbacksDelegator m_CallbacksDelegator = CallbacksDelegator.instance;
public override IEnumerator Execute(TestJobData testJobData)
{
if (testJobData.testTree != null)
{
yield break;
}
var assembliesEnumerator = m_testAssemblyProvider.GetAssembliesGroupedByTypeAsync(m_TestPlatform);
while (assembliesEnumerator.MoveNext())
{
yield return null;
}
if (assembliesEnumerator.Current == null)
{
throw new Exception("Assemblies not retrieved.");
}
var assemblies = assembliesEnumerator.Current.Where(pair => m_TestPlatform.IsFlagIncluded(pair.Key)).SelectMany(pair => pair.Value).Select(x => x.Assembly).ToArray();
var buildSettings = UnityTestAssemblyBuilder.GetNUnitTestBuilderSettings(m_TestPlatform);
var enumerator = m_testAssemblyBuilder.BuildAsync(assemblies, Enumerable.Repeat(m_TestPlatform, assemblies.Length).ToArray(), buildSettings);
while (enumerator.MoveNext())
{
yield return null;
}
var testList = enumerator.Current;
if (testList== null)
{
throw new Exception("Test list not retrieved.");
}
testList.ParseForNameDuplicates();
testJobData.testTree = testList;
m_CallbacksDelegator.TestTreeRebuild(testList);
}
}
}