Commit af571a61 authored by BlackAngle233's avatar BlackAngle233
Browse files

212

parent 1d9b5391
namespace UnityEditor.TestTools.TestRunner.Api namespace UnityEditor.TestTools.TestRunner.Api
{ {
internal interface ITestTreeRebuildCallbacks : ICallbacks internal interface ITestTreeRebuildCallbacks : ICallbacks
{ {
void TestTreeRebuild(ITestAdaptor test); void TestTreeRebuild(ITestAdaptor test);
} }
} }
\ No newline at end of file
fileFormatVersion: 2 fileFormatVersion: 2
guid: 4230e406313f1db43a4b548e7a3ad2e2 guid: 4230e406313f1db43a4b548e7a3ad2e2
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2
defaultReferences: [] defaultReferences: []
executionOrder: 0 executionOrder: 0
icon: {instanceID: 0} icon: {instanceID: 0}
userData: userData:
assetBundleName: assetBundleName:
assetBundleVariant: assetBundleVariant:
namespace UnityEditor.TestTools.TestRunner.Api namespace UnityEditor.TestTools.TestRunner.Api
{ {
public enum RunState public enum RunState
{ {
NotRunnable, NotRunnable,
Runnable, Runnable,
Explicit, Explicit,
Skipped, Skipped,
Ignored, Ignored,
} }
} }
fileFormatVersion: 2 fileFormatVersion: 2
guid: 8bb59cb2f66d156418ca1bd1e2703233 guid: 8bb59cb2f66d156418ca1bd1e2703233
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2
defaultReferences: [] defaultReferences: []
executionOrder: 0 executionOrder: 0
icon: {instanceID: 0} icon: {instanceID: 0}
userData: userData:
assetBundleName: assetBundleName:
assetBundleVariant: assetBundleVariant:
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using NUnit.Framework.Interfaces; using NUnit.Framework.Interfaces;
using NUnit.Framework.Internal; using NUnit.Framework.Internal;
using UnityEngine.TestRunner.NUnitExtensions; using UnityEngine.TestRunner.NUnitExtensions;
using UnityEngine.TestRunner.NUnitExtensions.Runner; using UnityEngine.TestRunner.NUnitExtensions.Runner;
using UnityEngine.TestRunner.TestLaunchers; using UnityEngine.TestRunner.TestLaunchers;
using UnityEngine.TestTools.Utils; using UnityEngine.TestTools.Utils;
namespace UnityEditor.TestTools.TestRunner.Api namespace UnityEditor.TestTools.TestRunner.Api
{ {
internal class TestAdaptor : ITestAdaptor internal class TestAdaptor : ITestAdaptor
{ {
internal TestAdaptor(ITest test, ITestAdaptor[] children = null) internal TestAdaptor(ITest test, ITestAdaptor[] children = null)
{ {
Id = test.Id; Id = test.Id;
Name = test.Name; Name = test.Name;
var childIndex = -1; var childIndex = -1;
if (test.Properties["childIndex"].Count > 0) if (test.Properties["childIndex"].Count > 0)
{ {
childIndex = (int)test.Properties["childIndex"][0]; childIndex = (int)test.Properties["childIndex"][0];
} }
FullName = childIndex != -1 ? GetIndexedTestCaseName(test.FullName, childIndex) : test.FullName; FullName = childIndex != -1 ? GetIndexedTestCaseName(test.FullName, childIndex) : test.FullName;
TestCaseCount = test.TestCaseCount; TestCaseCount = test.TestCaseCount;
HasChildren = test.HasChildren; HasChildren = test.HasChildren;
IsSuite = test.IsSuite; IsSuite = test.IsSuite;
if (UnityTestExecutionContext.CurrentContext != null) if (UnityTestExecutionContext.CurrentContext != null)
{ {
TestCaseTimeout = UnityTestExecutionContext.CurrentContext.TestCaseTimeout; TestCaseTimeout = UnityTestExecutionContext.CurrentContext.TestCaseTimeout;
} }
else else
{ {
TestCaseTimeout = CoroutineRunner.k_DefaultTimeout; TestCaseTimeout = CoroutineRunner.k_DefaultTimeout;
} }
TypeInfo = test.TypeInfo; TypeInfo = test.TypeInfo;
Method = test.Method; Method = test.Method;
Categories = test.GetAllCategoriesFromTest().Distinct().ToArray(); Categories = test.GetAllCategoriesFromTest().Distinct().ToArray();
IsTestAssembly = test is TestAssembly; IsTestAssembly = test is TestAssembly;
RunState = (RunState)Enum.Parse(typeof(RunState), test.RunState.ToString()); RunState = (RunState)Enum.Parse(typeof(RunState), test.RunState.ToString());
Description = (string)test.Properties.Get(PropertyNames.Description); Description = (string)test.Properties.Get(PropertyNames.Description);
SkipReason = test.GetSkipReason(); SkipReason = test.GetSkipReason();
ParentId = test.GetParentId(); ParentId = test.GetParentId();
ParentFullName = test.GetParentFullName(); ParentFullName = test.GetParentFullName();
UniqueName = test.GetUniqueName(); UniqueName = test.GetUniqueName();
ParentUniqueName = test.GetParentUniqueName(); ParentUniqueName = test.GetParentUniqueName();
ChildIndex = childIndex; ChildIndex = childIndex;
if (test.Parent != null) if (test.Parent != null)
{ {
if (test.Parent.Parent == null) // Assembly level if (test.Parent.Parent == null) // Assembly level
{ {
TestMode = (TestMode)Enum.Parse(typeof(TestMode),test.Properties.Get("platform").ToString()); TestMode = (TestMode)Enum.Parse(typeof(TestMode),test.Properties.Get("platform").ToString());
} }
} }
Children = children; Children = children;
} }
public void SetParent(ITestAdaptor parent) public void SetParent(ITestAdaptor parent)
{ {
Parent = parent; Parent = parent;
if (parent != null) if (parent != null)
{ {
TestMode = parent.TestMode; TestMode = parent.TestMode;
} }
} }
internal TestAdaptor(RemoteTestData test) internal TestAdaptor(RemoteTestData test)
{ {
Id = test.id; Id = test.id;
Name = test.name; Name = test.name;
FullName = test.ChildIndex != -1 ? GetIndexedTestCaseName(test.fullName, test.ChildIndex) : test.fullName; FullName = test.ChildIndex != -1 ? GetIndexedTestCaseName(test.fullName, test.ChildIndex) : test.fullName;
TestCaseCount = test.testCaseCount; TestCaseCount = test.testCaseCount;
HasChildren = test.hasChildren; HasChildren = test.hasChildren;
IsSuite = test.isSuite; IsSuite = test.isSuite;
m_ChildrenIds = test.childrenIds; m_ChildrenIds = test.childrenIds;
TestCaseTimeout = test.testCaseTimeout; TestCaseTimeout = test.testCaseTimeout;
Categories = test.Categories; Categories = test.Categories;
IsTestAssembly = test.IsTestAssembly; IsTestAssembly = test.IsTestAssembly;
RunState = (RunState)Enum.Parse(typeof(RunState), test.RunState.ToString()); RunState = (RunState)Enum.Parse(typeof(RunState), test.RunState.ToString());
Description = test.Description; Description = test.Description;
SkipReason = test.SkipReason; SkipReason = test.SkipReason;
ParentId = test.ParentId; ParentId = test.ParentId;
UniqueName = test.UniqueName; UniqueName = test.UniqueName;
ParentUniqueName = test.ParentUniqueName; ParentUniqueName = test.ParentUniqueName;
ParentFullName = test.ParentFullName; ParentFullName = test.ParentFullName;
ChildIndex = test.ChildIndex; ChildIndex = test.ChildIndex;
TestMode = TestMode.PlayMode; TestMode = TestMode.PlayMode;
} }
internal void ApplyChildren(IEnumerable<TestAdaptor> allTests) internal void ApplyChildren(IEnumerable<TestAdaptor> allTests)
{ {
Children = m_ChildrenIds.Select(id => allTests.First(t => t.Id == id)).ToArray(); Children = m_ChildrenIds.Select(id => allTests.First(t => t.Id == id)).ToArray();
if (!string.IsNullOrEmpty(ParentId)) if (!string.IsNullOrEmpty(ParentId))
{ {
Parent = allTests.FirstOrDefault(t => t.Id == ParentId); Parent = allTests.FirstOrDefault(t => t.Id == ParentId);
} }
} }
public string Id { get; private set; } public string Id { get; private set; }
public string Name { get; private set; } public string Name { get; private set; }
public string FullName { get; private set; } public string FullName { get; private set; }
public int TestCaseCount { get; private set; } public int TestCaseCount { get; private set; }
public bool HasChildren { get; private set; } public bool HasChildren { get; private set; }
public bool IsSuite { get; private set; } public bool IsSuite { get; private set; }
public IEnumerable<ITestAdaptor> Children { get; private set; } public IEnumerable<ITestAdaptor> Children { get; private set; }
public ITestAdaptor Parent { get; private set; } public ITestAdaptor Parent { get; private set; }
public int TestCaseTimeout { get; private set; } public int TestCaseTimeout { get; private set; }
public ITypeInfo TypeInfo { get; private set; } public ITypeInfo TypeInfo { get; private set; }
public IMethodInfo Method { get; private set; } public IMethodInfo Method { get; private set; }
private string[] m_ChildrenIds; private string[] m_ChildrenIds;
public string[] Categories { get; private set; } public string[] Categories { get; private set; }
public bool IsTestAssembly { get; private set; } public bool IsTestAssembly { get; private set; }
public RunState RunState { get; } public RunState RunState { get; }
public string Description { get; } public string Description { get; }
public string SkipReason { get; } public string SkipReason { get; }
public string ParentId { get; } public string ParentId { get; }
public string ParentFullName { get; } public string ParentFullName { get; }
public string UniqueName { get; } public string UniqueName { get; }
public string ParentUniqueName { get; } public string ParentUniqueName { get; }
public int ChildIndex { get; } public int ChildIndex { get; }
public TestMode TestMode { get; private set; } public TestMode TestMode { get; private set; }
private static string GetIndexedTestCaseName(string fullName, int index) private static string GetIndexedTestCaseName(string fullName, int index)
{ {
var generatedTestSuffix = " GeneratedTestCase" + index; var generatedTestSuffix = " GeneratedTestCase" + index;
if (fullName.EndsWith(")")) if (fullName.EndsWith(")"))
{ {
// Test names from generated TestCaseSource look like Test(TestCaseSourceType) // Test names from generated TestCaseSource look like Test(TestCaseSourceType)
// This inserts a unique test case index in the name, so that it becomes Test(TestCaseSourceType GeneratedTestCase0) // This inserts a unique test case index in the name, so that it becomes Test(TestCaseSourceType GeneratedTestCase0)
return fullName.Substring(0, fullName.Length - 1) + generatedTestSuffix + fullName[fullName.Length - 1]; return fullName.Substring(0, fullName.Length - 1) + generatedTestSuffix + fullName[fullName.Length - 1];
} }
// In some cases there can be tests with duplicate names generated in other ways and they won't have () in their name // In some cases there can be tests with duplicate names generated in other ways and they won't have () in their name
// We just append a suffix at the end of the name in that case // We just append a suffix at the end of the name in that case
return fullName + generatedTestSuffix; return fullName + generatedTestSuffix;
} }
} }
} }
fileFormatVersion: 2 fileFormatVersion: 2
guid: 6e0e62db88935c74288c97c907243bd0 guid: 6e0e62db88935c74288c97c907243bd0
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2
defaultReferences: [] defaultReferences: []
executionOrder: 0 executionOrder: 0
icon: {instanceID: 0} icon: {instanceID: 0}
userData: userData:
assetBundleName: assetBundleName:
assetBundleVariant: assetBundleVariant:
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using NUnit.Framework.Interfaces; using NUnit.Framework.Interfaces;
using UnityEngine.TestRunner.NUnitExtensions; using UnityEngine.TestRunner.NUnitExtensions;
using UnityEngine.TestRunner.TestLaunchers; using UnityEngine.TestRunner.TestLaunchers;
namespace UnityEditor.TestTools.TestRunner.Api namespace UnityEditor.TestTools.TestRunner.Api
{ {
internal class TestAdaptorFactory : ITestAdaptorFactory internal class TestAdaptorFactory : ITestAdaptorFactory
{ {
private Dictionary<string, TestAdaptor> m_TestAdaptorCache = new Dictionary<string, TestAdaptor>(); private Dictionary<string, TestAdaptor> m_TestAdaptorCache = new Dictionary<string, TestAdaptor>();
private Dictionary<string, TestResultAdaptor> m_TestResultAdaptorCache = new Dictionary<string, TestResultAdaptor>(); private Dictionary<string, TestResultAdaptor> m_TestResultAdaptorCache = new Dictionary<string, TestResultAdaptor>();
public ITestAdaptor Create(ITest test) public ITestAdaptor Create(ITest test)
{ {
var uniqueName = test.GetUniqueName(); var uniqueName = test.GetUniqueName();
if (m_TestAdaptorCache.ContainsKey(uniqueName)) if (m_TestAdaptorCache.ContainsKey(uniqueName))
{ {
return m_TestAdaptorCache[uniqueName]; return m_TestAdaptorCache[uniqueName];
} }
var adaptor = new TestAdaptor(test, test.Tests.Select(Create).ToArray()); var adaptor = new TestAdaptor(test, test.Tests.Select(Create).ToArray());
foreach (var child in adaptor.Children) foreach (var child in adaptor.Children)
{ {
(child as TestAdaptor).SetParent(adaptor); (child as TestAdaptor).SetParent(adaptor);
} }
m_TestAdaptorCache[uniqueName] = adaptor; m_TestAdaptorCache[uniqueName] = adaptor;
return adaptor; return adaptor;
} }
public ITestAdaptor Create(RemoteTestData testData) public ITestAdaptor Create(RemoteTestData testData)
{ {
return new TestAdaptor(testData); return new TestAdaptor(testData);
} }
public ITestResultAdaptor Create(ITestResult testResult) public ITestResultAdaptor Create(ITestResult testResult)
{ {
var uniqueName = testResult.Test.GetUniqueName(); var uniqueName = testResult.Test.GetUniqueName();
if (m_TestResultAdaptorCache.ContainsKey(uniqueName)) if (m_TestResultAdaptorCache.ContainsKey(uniqueName))
{ {
return m_TestResultAdaptorCache[uniqueName]; return m_TestResultAdaptorCache[uniqueName];
} }
var adaptor = new TestResultAdaptor(testResult, Create(testResult.Test), testResult.Children.Select(Create).ToArray()); var adaptor = new TestResultAdaptor(testResult, Create(testResult.Test), testResult.Children.Select(Create).ToArray());
m_TestResultAdaptorCache[uniqueName] = adaptor; m_TestResultAdaptorCache[uniqueName] = adaptor;
return adaptor; return adaptor;
} }
public ITestResultAdaptor Create(RemoteTestResultData testResult, RemoteTestResultDataWithTestData allData) public ITestResultAdaptor Create(RemoteTestResultData testResult, RemoteTestResultDataWithTestData allData)
{ {
return new TestResultAdaptor(testResult, allData); return new TestResultAdaptor(testResult, allData);
} }
public ITestAdaptor BuildTree(RemoteTestResultDataWithTestData data) public ITestAdaptor BuildTree(RemoteTestResultDataWithTestData data)
{ {
var tests = data.tests.Select(remoteTestData => new TestAdaptor(remoteTestData)).ToList(); var tests = data.tests.Select(remoteTestData => new TestAdaptor(remoteTestData)).ToList();
foreach (var test in tests) foreach (var test in tests)
{ {
test.ApplyChildren(tests); test.ApplyChildren(tests);
} }
return tests.First(); return tests.First();
} }
public IEnumerator<ITestAdaptor> BuildTreeAsync(RemoteTestResultDataWithTestData data) public IEnumerator<ITestAdaptor> BuildTreeAsync(RemoteTestResultDataWithTestData data)
{ {
var tests = data.tests.Select(remoteTestData => new TestAdaptor(remoteTestData)).ToList(); var tests = data.tests.Select(remoteTestData => new TestAdaptor(remoteTestData)).ToList();
for (var index = 0; index < tests.Count; index++) for (var index = 0; index < tests.Count; index++)
{ {
var test = tests[index]; var test = tests[index];
test.ApplyChildren(tests); test.ApplyChildren(tests);
if (index % 100 == 0) if (index % 100 == 0)
{ {
yield return null; yield return null;
} }
} }
yield return tests.First(); yield return tests.First();
} }
public void ClearResultsCache() public void ClearResultsCache()
{ {
m_TestResultAdaptorCache.Clear(); m_TestResultAdaptorCache.Clear();
} }
public void ClearTestsCache() public void ClearTestsCache()
{ {
m_TestAdaptorCache.Clear(); m_TestAdaptorCache.Clear();
} }
} }
} }
fileFormatVersion: 2 fileFormatVersion: 2
guid: d0663d520c26b7c48a4135599e66acf8 guid: d0663d520c26b7c48a4135599e66acf8
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2
defaultReferences: [] defaultReferences: []
executionOrder: 0 executionOrder: 0
icon: {instanceID: 0} icon: {instanceID: 0}
userData: userData:
assetBundleName: assetBundleName:
assetBundleVariant: assetBundleVariant:
using System; using System;
namespace UnityEditor.TestTools.TestRunner.Api namespace UnityEditor.TestTools.TestRunner.Api
{ {
[Flags] [Flags]
public enum TestMode public enum TestMode
{ {
EditMode = 1 << 0, EditMode = 1 << 0,
PlayMode = 1 << 1 PlayMode = 1 << 1
} }
} }
fileFormatVersion: 2 fileFormatVersion: 2
guid: cad095eccea17b741bc4cd264e7441cd guid: cad095eccea17b741bc4cd264e7441cd
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2
defaultReferences: [] defaultReferences: []
executionOrder: 0 executionOrder: 0
icon: {instanceID: 0} icon: {instanceID: 0}
userData: userData:
assetBundleName: assetBundleName:
assetBundleVariant: assetBundleVariant:
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using NUnit.Framework.Interfaces; using NUnit.Framework.Interfaces;
using UnityEngine.TestRunner.TestLaunchers; using UnityEngine.TestRunner.TestLaunchers;
namespace UnityEditor.TestTools.TestRunner.Api namespace UnityEditor.TestTools.TestRunner.Api
{ {
internal class TestResultAdaptor : ITestResultAdaptor internal class TestResultAdaptor : ITestResultAdaptor
{ {
private TNode m_Node; private TNode m_Node;
internal TestResultAdaptor(ITestResult result, ITestAdaptor test, ITestResultAdaptor[] children = null) internal TestResultAdaptor(ITestResult result, ITestAdaptor test, ITestResultAdaptor[] children = null)
{ {
Test = test; Test = test;
Name = result.Name; Name = result.Name;
FullName = result.FullName; FullName = result.FullName;
ResultState = result.ResultState.ToString(); ResultState = result.ResultState.ToString();
TestStatus = ParseTestStatus(result.ResultState.Status); TestStatus = ParseTestStatus(result.ResultState.Status);
Duration = result.Duration; Duration = result.Duration;
StartTime = result.StartTime; StartTime = result.StartTime;
EndTime = result.EndTime; EndTime = result.EndTime;
Message = result.Message; Message = result.Message;
StackTrace = result.StackTrace; StackTrace = result.StackTrace;
AssertCount = result.AssertCount; AssertCount = result.AssertCount;
FailCount = result.FailCount; FailCount = result.FailCount;
PassCount = result.PassCount; PassCount = result.PassCount;
SkipCount = result.SkipCount; SkipCount = result.SkipCount;
InconclusiveCount = result.InconclusiveCount; InconclusiveCount = result.InconclusiveCount;
HasChildren = result.HasChildren; HasChildren = result.HasChildren;
Output = result.Output; Output = result.Output;
Children = children; Children = children;
m_Node = result.ToXml(true); m_Node = result.ToXml(true);
} }
internal TestResultAdaptor(RemoteTestResultData result, RemoteTestResultDataWithTestData allData) internal TestResultAdaptor(RemoteTestResultData result, RemoteTestResultDataWithTestData allData)
{ {
Test = new TestAdaptor(allData.tests.First(t => t.id == result.testId)); Test = new TestAdaptor(allData.tests.First(t => t.id == result.testId));
Name = result.name; Name = result.name;
FullName = result.fullName; FullName = result.fullName;
ResultState = result.resultState; ResultState = result.resultState;
TestStatus = ParseTestStatus(result.testStatus); TestStatus = ParseTestStatus(result.testStatus);
Duration = result.duration; Duration = result.duration;
StartTime = result.startTime; StartTime = result.startTime;
EndTime = result.endTime; EndTime = result.endTime;
Message = result.message; Message = result.message;
StackTrace = result.stackTrace; StackTrace = result.stackTrace;
AssertCount = result.assertCount; AssertCount = result.assertCount;
FailCount = result.failCount; FailCount = result.failCount;
PassCount = result.passCount; PassCount = result.passCount;
SkipCount = result.skipCount; SkipCount = result.skipCount;
InconclusiveCount = result.inconclusiveCount; InconclusiveCount = result.inconclusiveCount;
HasChildren = result.hasChildren; HasChildren = result.hasChildren;
Output = result.output; Output = result.output;
Children = result.childrenIds.Select(childId => new TestResultAdaptor(allData.results.First(r => r.testId == childId), allData)).ToArray(); Children = result.childrenIds.Select(childId => new TestResultAdaptor(allData.results.First(r => r.testId == childId), allData)).ToArray();
m_Node = TNode.FromXml(result.xml); m_Node = TNode.FromXml(result.xml);
} }
public ITestAdaptor Test { get; private set; } public ITestAdaptor Test { get; private set; }
public string Name { get; private set; } public string Name { get; private set; }
public string FullName { get; private set; } public string FullName { get; private set; }
public string ResultState { get; private set; } public string ResultState { get; private set; }
public TestStatus TestStatus { get; private set; } public TestStatus TestStatus { get; private set; }
public double Duration { get; private set; } public double Duration { get; private set; }
public DateTime StartTime { get; private set; } public DateTime StartTime { get; private set; }
public DateTime EndTime { get; private set; } public DateTime EndTime { get; private set; }
public string Message { get; private set; } public string Message { get; private set; }
public string StackTrace { get; private set; } public string StackTrace { get; private set; }
public int AssertCount { get; private set; } public int AssertCount { get; private set; }
public int FailCount { get; private set; } public int FailCount { get; private set; }
public int PassCount { get; private set; } public int PassCount { get; private set; }
public int SkipCount { get; private set; } public int SkipCount { get; private set; }
public int InconclusiveCount { get; private set; } public int InconclusiveCount { get; private set; }
public bool HasChildren { get; private set; } public bool HasChildren { get; private set; }
public IEnumerable<ITestResultAdaptor> Children { get; private set; } public IEnumerable<ITestResultAdaptor> Children { get; private set; }
public string Output { get; private set; } public string Output { get; private set; }
public TNode ToXml() public TNode ToXml()
{ {
return m_Node; return m_Node;
} }
private static TestStatus ParseTestStatus(NUnit.Framework.Interfaces.TestStatus testStatus) private static TestStatus ParseTestStatus(NUnit.Framework.Interfaces.TestStatus testStatus)
{ {
return (TestStatus)Enum.Parse(typeof(TestStatus), testStatus.ToString()); return (TestStatus)Enum.Parse(typeof(TestStatus), testStatus.ToString());
} }
} }
} }
fileFormatVersion: 2 fileFormatVersion: 2
guid: d061ada5d3169454daf54243390b5fdb guid: d061ada5d3169454daf54243390b5fdb
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2
defaultReferences: [] defaultReferences: []
executionOrder: 0 executionOrder: 0
icon: {instanceID: 0} icon: {instanceID: 0}
userData: userData:
assetBundleName: assetBundleName:
assetBundleVariant: assetBundleVariant:
using System; using System;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using UnityEditor.TestTools.TestRunner.CommandLineTest; using UnityEditor.TestTools.TestRunner.CommandLineTest;
using UnityEditor.TestTools.TestRunner.TestRun; using UnityEditor.TestTools.TestRunner.TestRun;
using UnityEngine; using UnityEngine;
using UnityEngine.TestRunner.TestLaunchers; using UnityEngine.TestRunner.TestLaunchers;
using UnityEngine.TestTools; using UnityEngine.TestTools;
using UnityEngine.TestTools.NUnitExtensions; using UnityEngine.TestTools.NUnitExtensions;
namespace UnityEditor.TestTools.TestRunner.Api namespace UnityEditor.TestTools.TestRunner.Api
{ {
public class TestRunnerApi : ScriptableObject, ITestRunnerApi public class TestRunnerApi : ScriptableObject, ITestRunnerApi
{ {
internal ICallbacksHolder callbacksHolder; internal ICallbacksHolder callbacksHolder;
private ICallbacksHolder m_CallbacksHolder private ICallbacksHolder m_CallbacksHolder
{ {
get get
{ {
if (callbacksHolder == null) if (callbacksHolder == null)
{ {
return CallbacksHolder.instance; return CallbacksHolder.instance;
} }
return callbacksHolder; return callbacksHolder;
} }
} }
internal Func<ExecutionSettings,string> ScheduleJob = (executionSettings) => internal Func<ExecutionSettings,string> ScheduleJob = (executionSettings) =>
{ {
var runner = new TestJobRunner(); var runner = new TestJobRunner();
return runner.RunJob(new TestJobData(executionSettings)); return runner.RunJob(new TestJobData(executionSettings));
}; };
public string Execute(ExecutionSettings executionSettings) public string Execute(ExecutionSettings executionSettings)
{ {
if (executionSettings == null) if (executionSettings == null)
{ {
throw new ArgumentNullException(nameof(executionSettings)); throw new ArgumentNullException(nameof(executionSettings));
} }
if ((executionSettings.filters == null || executionSettings.filters.Length == 0) && executionSettings.filter != null) if ((executionSettings.filters == null || executionSettings.filters.Length == 0) && executionSettings.filter != null)
{ {
// Map filter (singular) to filters (plural), for backwards compatibility. // Map filter (singular) to filters (plural), for backwards compatibility.
executionSettings.filters = new [] {executionSettings.filter}; executionSettings.filters = new [] {executionSettings.filter};
} }
if (executionSettings.targetPlatform == null && executionSettings.filters != null && if (executionSettings.targetPlatform == null && executionSettings.filters != null &&
executionSettings.filters.Length > 0) executionSettings.filters.Length > 0)
{ {
executionSettings.targetPlatform = executionSettings.filters[0].targetPlatform; executionSettings.targetPlatform = executionSettings.filters[0].targetPlatform;
} }
return ScheduleJob(executionSettings); return ScheduleJob(executionSettings);
} }
public void RegisterCallbacks<T>(T testCallbacks, int priority = 0) where T : ICallbacks public void RegisterCallbacks<T>(T testCallbacks, int priority = 0) where T : ICallbacks
{ {
if (testCallbacks == null) if (testCallbacks == null)
{ {
throw new ArgumentNullException(nameof(testCallbacks)); throw new ArgumentNullException(nameof(testCallbacks));
} }
m_CallbacksHolder.Add(testCallbacks, priority); m_CallbacksHolder.Add(testCallbacks, priority);
} }
public void UnregisterCallbacks<T>(T testCallbacks) where T : ICallbacks public void UnregisterCallbacks<T>(T testCallbacks) where T : ICallbacks
{ {
if (testCallbacks == null) if (testCallbacks == null)
{ {
throw new ArgumentNullException(nameof(testCallbacks)); throw new ArgumentNullException(nameof(testCallbacks));
} }
m_CallbacksHolder.Remove(testCallbacks); m_CallbacksHolder.Remove(testCallbacks);
} }
internal void RetrieveTestList(ExecutionSettings executionSettings, Action<ITestAdaptor> callback) internal void RetrieveTestList(ExecutionSettings executionSettings, Action<ITestAdaptor> callback)
{ {
if (executionSettings == null) if (executionSettings == null)
{ {
throw new ArgumentNullException(nameof(executionSettings)); throw new ArgumentNullException(nameof(executionSettings));
} }
var firstFilter = executionSettings.filters?.FirstOrDefault() ?? executionSettings.filter; var firstFilter = executionSettings.filters?.FirstOrDefault() ?? executionSettings.filter;
RetrieveTestList(firstFilter.testMode, callback); RetrieveTestList(firstFilter.testMode, callback);
} }
public void RetrieveTestList(TestMode testMode, Action<ITestAdaptor> callback) public void RetrieveTestList(TestMode testMode, Action<ITestAdaptor> callback)
{ {
if (callback == null) if (callback == null)
{ {
throw new ArgumentNullException(nameof(callback)); throw new ArgumentNullException(nameof(callback));
} }
var platform = ParseTestMode(testMode); var platform = ParseTestMode(testMode);
var testAssemblyProvider = new EditorLoadedTestAssemblyProvider(new EditorCompilationInterfaceProxy(), new EditorAssembliesProxy()); var testAssemblyProvider = new EditorLoadedTestAssemblyProvider(new EditorCompilationInterfaceProxy(), new EditorAssembliesProxy());
var testAdaptorFactory = new TestAdaptorFactory(); var testAdaptorFactory = new TestAdaptorFactory();
var testListCache = new TestListCache(testAdaptorFactory, new RemoteTestResultDataFactory(), TestListCacheData.instance); var testListCache = new TestListCache(testAdaptorFactory, new RemoteTestResultDataFactory(), TestListCacheData.instance);
var testListProvider = new TestListProvider(testAssemblyProvider, new UnityTestAssemblyBuilder()); var testListProvider = new TestListProvider(testAssemblyProvider, new UnityTestAssemblyBuilder());
var cachedTestListProvider = new CachingTestListProvider(testListProvider, testListCache, testAdaptorFactory); var cachedTestListProvider = new CachingTestListProvider(testListProvider, testListCache, testAdaptorFactory);
var job = new TestListJob(cachedTestListProvider, platform, (testRoot) => var job = new TestListJob(cachedTestListProvider, platform, (testRoot) =>
{ {
callback(testRoot); callback(testRoot);
}); });
job.Start(); job.Start();
} }
internal static bool IsRunActive() internal static bool IsRunActive()
{ {
return RunData.instance.isRunning; return RunData.instance.isRunning;
} }
private static TestPlatform ParseTestMode(TestMode testMode) private static TestPlatform ParseTestMode(TestMode testMode)
{ {
return (((testMode & TestMode.EditMode) == TestMode.EditMode) ? TestPlatform.EditMode : 0) | (((testMode & TestMode.PlayMode) == TestMode.PlayMode) ? TestPlatform.PlayMode : 0); return (((testMode & TestMode.EditMode) == TestMode.EditMode) ? TestPlatform.EditMode : 0) | (((testMode & TestMode.PlayMode) == TestMode.PlayMode) ? TestPlatform.PlayMode : 0);
} }
} }
} }
fileFormatVersion: 2 fileFormatVersion: 2
guid: 68993ba529ae04440916cb7c23bf3279 guid: 68993ba529ae04440916cb7c23bf3279
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2
defaultReferences: [] defaultReferences: []
executionOrder: 0 executionOrder: 0
icon: {instanceID: 0} icon: {instanceID: 0}
userData: userData:
assetBundleName: assetBundleName:
assetBundleVariant: assetBundleVariant:
namespace UnityEditor.TestTools.TestRunner.Api namespace UnityEditor.TestTools.TestRunner.Api
{ {
public enum TestStatus public enum TestStatus
{ {
Inconclusive, Inconclusive,
Skipped, Skipped,
Passed, Passed,
Failed Failed
} }
} }
fileFormatVersion: 2 fileFormatVersion: 2
guid: 9ec94545c5b00344c9bd8e691f15d799 guid: 9ec94545c5b00344c9bd8e691f15d799
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2
defaultReferences: [] defaultReferences: []
executionOrder: 0 executionOrder: 0
icon: {instanceID: 0} icon: {instanceID: 0}
userData: userData:
assetBundleName: assetBundleName:
assetBundleVariant: assetBundleVariant:
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
[assembly: AssemblyTitle("UnityEditor.TestRunner")] [assembly: AssemblyTitle("UnityEditor.TestRunner")]
[assembly: InternalsVisibleTo("Assembly-CSharp-Editor-testable")] [assembly: InternalsVisibleTo("Assembly-CSharp-Editor-testable")]
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] [assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
[assembly: InternalsVisibleTo("Unity.PerformanceTesting.Editor")] [assembly: InternalsVisibleTo("Unity.PerformanceTesting.Editor")]
[assembly: InternalsVisibleTo("Unity.IntegrationTests")] [assembly: InternalsVisibleTo("Unity.IntegrationTests")]
[assembly: InternalsVisibleTo("UnityEditor.TestRunner.Tests")] [assembly: InternalsVisibleTo("UnityEditor.TestRunner.Tests")]
[assembly: InternalsVisibleTo("Unity.TestTools.CodeCoverage.Editor")] [assembly: InternalsVisibleTo("Unity.TestTools.CodeCoverage.Editor")]
[assembly: InternalsVisibleTo("Unity.PackageManagerUI.Develop.Editor")] [assembly: InternalsVisibleTo("Unity.PackageManagerUI.Develop.Editor")]
[assembly: InternalsVisibleTo("Unity.PackageManagerUI.Develop.EditorTests")] [assembly: InternalsVisibleTo("Unity.PackageManagerUI.Develop.EditorTests")]
[assembly: InternalsVisibleTo("Unity.PackageValidationSuite.Editor")] [assembly: InternalsVisibleTo("Unity.PackageValidationSuite.Editor")]
[assembly: AssemblyVersion("1.0.0")] [assembly: AssemblyVersion("1.0.0")]
fileFormatVersion: 2 fileFormatVersion: 2
guid: 9db19a04003fca7439552acd4de9baa1 guid: 9db19a04003fca7439552acd4de9baa1
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2
defaultReferences: [] defaultReferences: []
executionOrder: 0 executionOrder: 0
icon: {instanceID: 0} icon: {instanceID: 0}
userData: userData:
assetBundleName: assetBundleName:
assetBundleVariant: assetBundleVariant:
fileFormatVersion: 2 fileFormatVersion: 2
guid: 7602252bdb82b8d45ae3483c3a00d3e1 guid: 7602252bdb82b8d45ae3483c3a00d3e1
folderAsset: yes folderAsset: yes
DefaultImporter: DefaultImporter:
externalObjects: {} externalObjects: {}
userData: userData:
assetBundleName: assetBundleName:
assetBundleVariant: assetBundleVariant:
using System; using System;
using System.Linq; using System.Linq;
namespace UnityEditor.TestRunner.CommandLineParser namespace UnityEditor.TestRunner.CommandLineParser
{ {
internal class CommandLineOption : ICommandLineOption internal class CommandLineOption : ICommandLineOption
{ {
Action<string> m_ArgAction; Action<string> m_ArgAction;
public CommandLineOption(string argName, Action action) public CommandLineOption(string argName, Action action)
{ {
ArgName = argName; ArgName = argName;
m_ArgAction = s => action(); m_ArgAction = s => action();
} }
public CommandLineOption(string argName, Action<string> action) public CommandLineOption(string argName, Action<string> action)
{ {
ArgName = argName; ArgName = argName;
m_ArgAction = action; m_ArgAction = action;
} }
public CommandLineOption(string argName, Action<string[]> action) public CommandLineOption(string argName, Action<string[]> action)
{ {
ArgName = argName; ArgName = argName;
m_ArgAction = s => action(SplitStringToArray(s)); m_ArgAction = s => action(SplitStringToArray(s));
} }
public string ArgName { get; private set; } public string ArgName { get; private set; }
public void ApplyValue(string value) public void ApplyValue(string value)
{ {
m_ArgAction(value); m_ArgAction(value);
} }
static string[] SplitStringToArray(string value) static string[] SplitStringToArray(string value)
{ {
if (string.IsNullOrEmpty(value)) if (string.IsNullOrEmpty(value))
{ {
return null; return null;
} }
return value.Split(';').ToArray(); return value.Split(';').ToArray();
} }
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment