initial project folder
This commit is contained in:
@ -0,0 +1,116 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework.Interfaces;
|
||||
using NUnit.Framework.Internal;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestRunner.TestLaunchers;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner.Api
|
||||
{
|
||||
internal class CallbacksDelegator
|
||||
{
|
||||
private static CallbacksDelegator s_instance;
|
||||
public static CallbacksDelegator instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (s_instance == null)
|
||||
{
|
||||
s_instance = new CallbacksDelegator(CallbacksHolder.instance.GetAll, new TestAdaptorFactory());
|
||||
}
|
||||
return s_instance;
|
||||
}
|
||||
}
|
||||
|
||||
private readonly Func<ICallbacks[]> m_CallbacksProvider;
|
||||
private readonly ITestAdaptorFactory m_AdaptorFactory;
|
||||
|
||||
public CallbacksDelegator(Func<ICallbacks[]> callbacksProvider, ITestAdaptorFactory adaptorFactory)
|
||||
{
|
||||
m_CallbacksProvider = callbacksProvider;
|
||||
m_AdaptorFactory = adaptorFactory;
|
||||
}
|
||||
|
||||
public void RunStarted(ITest testsToRun)
|
||||
{
|
||||
var testRunnerTestsToRun = m_AdaptorFactory.Create(testsToRun);
|
||||
TryInvokeAllCallbacks(callbacks => callbacks.RunStarted(testRunnerTestsToRun));
|
||||
}
|
||||
|
||||
public void RunStartedRemotely(byte[] testsToRunData)
|
||||
{
|
||||
var testData = Deserialize<RemoteTestResultDataWithTestData>(testsToRunData);
|
||||
var testsToRun = m_AdaptorFactory.BuildTree(testData);
|
||||
TryInvokeAllCallbacks(callbacks => callbacks.RunStarted(testsToRun));
|
||||
}
|
||||
|
||||
public void RunFinished(ITestResult testResults)
|
||||
{
|
||||
var testResult = m_AdaptorFactory.Create(testResults);
|
||||
TryInvokeAllCallbacks(callbacks => callbacks.RunFinished(testResult));
|
||||
}
|
||||
|
||||
public void RunFinishedRemotely(byte[] testResultsData)
|
||||
{
|
||||
var remoteTestResult = Deserialize<RemoteTestResultDataWithTestData>(testResultsData);
|
||||
var testResult = m_AdaptorFactory.Create(remoteTestResult.results.First(), remoteTestResult);
|
||||
TryInvokeAllCallbacks(callbacks => callbacks.RunFinished(testResult));
|
||||
}
|
||||
|
||||
public void RunFailed(string failureMessage)
|
||||
{
|
||||
var nunitTestResult = new TestSuiteResult(new TestSuite("test"));
|
||||
nunitTestResult.SetResult(ResultState.Error, failureMessage);
|
||||
var testResult = m_AdaptorFactory.Create(nunitTestResult);
|
||||
TryInvokeAllCallbacks(callbacks => callbacks.RunFinished(testResult));
|
||||
}
|
||||
|
||||
public void TestStarted(ITest test)
|
||||
{
|
||||
var testRunnerTest = m_AdaptorFactory.Create(test);
|
||||
TryInvokeAllCallbacks(callbacks => callbacks.TestStarted(testRunnerTest));
|
||||
}
|
||||
|
||||
public void TestStartedRemotely(byte[] testStartedData)
|
||||
{
|
||||
var testData = Deserialize<RemoteTestResultDataWithTestData>(testStartedData);
|
||||
var testsToRun = m_AdaptorFactory.BuildTree(testData);
|
||||
|
||||
TryInvokeAllCallbacks(callbacks => callbacks.TestStarted(testsToRun));
|
||||
}
|
||||
|
||||
public void TestFinished(ITestResult result)
|
||||
{
|
||||
var testResult = m_AdaptorFactory.Create(result);
|
||||
TryInvokeAllCallbacks(callbacks => callbacks.TestFinished(testResult));
|
||||
}
|
||||
|
||||
public void TestFinishedRemotely(byte[] testResultsData)
|
||||
{
|
||||
var remoteTestResult = Deserialize<RemoteTestResultDataWithTestData>(testResultsData);
|
||||
var testResult = m_AdaptorFactory.Create(remoteTestResult.results.First(), remoteTestResult);
|
||||
TryInvokeAllCallbacks(callbacks => callbacks.TestFinished(testResult));
|
||||
}
|
||||
|
||||
private void TryInvokeAllCallbacks(Action<ICallbacks> callbackAction)
|
||||
{
|
||||
foreach (var testRunnerApiCallback in m_CallbacksProvider())
|
||||
{
|
||||
try
|
||||
{
|
||||
callbackAction(testRunnerApiCallback);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static T Deserialize<T>(byte[] data)
|
||||
{
|
||||
return JsonUtility.FromJson<T>(Encoding.UTF8.GetString(data));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0de03ebd74e2b474fa23d05ab42d0cd8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,28 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools.TestRunner;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner.Api
|
||||
{
|
||||
internal class CallbacksDelegatorListener : ScriptableObject, ITestRunnerListener
|
||||
{
|
||||
public void RunStarted(NUnit.Framework.Interfaces.ITest testsToRun)
|
||||
{
|
||||
CallbacksDelegator.instance.RunStarted(testsToRun);
|
||||
}
|
||||
|
||||
public void RunFinished(NUnit.Framework.Interfaces.ITestResult testResults)
|
||||
{
|
||||
CallbacksDelegator.instance.RunFinished(testResults);
|
||||
}
|
||||
|
||||
public void TestStarted(NUnit.Framework.Interfaces.ITest test)
|
||||
{
|
||||
CallbacksDelegator.instance.TestStarted(test);
|
||||
}
|
||||
|
||||
public void TestFinished(NUnit.Framework.Interfaces.ITestResult result)
|
||||
{
|
||||
CallbacksDelegator.instance.TestFinished(result);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f3e1b3cbf3fac6a459b1a602167ad311
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,40 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner.Api
|
||||
{
|
||||
internal class CallbacksHolder : ScriptableSingleton<CallbacksHolder>
|
||||
{
|
||||
private List<CallbackWithPriority> m_Callbacks = new List<CallbackWithPriority>();
|
||||
public void Add(ICallbacks callback, int priority)
|
||||
{
|
||||
m_Callbacks.Add(new CallbackWithPriority(callback, priority));
|
||||
}
|
||||
|
||||
public void Remove(ICallbacks callback)
|
||||
{
|
||||
m_Callbacks.RemoveAll(callbackWithPriority => callbackWithPriority.Callback == callback);
|
||||
}
|
||||
|
||||
public ICallbacks[] GetAll()
|
||||
{
|
||||
return m_Callbacks.OrderByDescending(callback => callback.Priority).Select(callback => callback.Callback).ToArray();
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
m_Callbacks.Clear();
|
||||
}
|
||||
|
||||
private struct CallbackWithPriority
|
||||
{
|
||||
public ICallbacks Callback;
|
||||
public int Priority;
|
||||
public CallbackWithPriority(ICallbacks callback, int priority)
|
||||
{
|
||||
Callback = callback;
|
||||
Priority = priority;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4884ccc3528cb2e40a0e6f0a19a2b35b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,9 @@
|
||||
namespace UnityEditor.TestTools.TestRunner.Api
|
||||
{
|
||||
internal class ExecutionSettings
|
||||
{
|
||||
public BuildTarget? targetPlatform;
|
||||
public ITestRunSettings overloadTestRunSettings;
|
||||
public Filter filter;
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eea34a28297f9bc4c9f4c573bc8d5d1c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools.TestRunner.GUI;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner.Api
|
||||
{
|
||||
[Serializable]
|
||||
internal class Filter
|
||||
{
|
||||
[SerializeField]
|
||||
public TestMode testMode;
|
||||
[SerializeField]
|
||||
public string[] testNames;
|
||||
[SerializeField]
|
||||
public string[] groupNames;
|
||||
[SerializeField]
|
||||
public string[] categoryNames;
|
||||
[SerializeField]
|
||||
public string[] assemblyNames;
|
||||
|
||||
public static Filter empty = new Filter();
|
||||
|
||||
internal TestRunnerFilter ToTestRunnerFilter()
|
||||
{
|
||||
return new TestRunnerFilter()
|
||||
{
|
||||
testNames = testNames,
|
||||
categoryNames = categoryNames,
|
||||
groupNames = groupNames,
|
||||
assemblyNames = assemblyNames
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 05f92e4a2414cb144a92157752dfa324
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,10 @@
|
||||
namespace UnityEditor.TestTools.TestRunner.Api
|
||||
{
|
||||
internal interface ICallbacks
|
||||
{
|
||||
void RunStarted(ITestAdaptor testsToRun);
|
||||
void RunFinished(ITestResultAdaptor result);
|
||||
void TestStarted(ITestAdaptor test);
|
||||
void TestFinished(ITestResultAdaptor result);
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 93eea84e53d0226479c9a584f19427b5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,27 @@
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework.Interfaces;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner.Api
|
||||
{
|
||||
internal interface ITestAdaptor
|
||||
{
|
||||
string Id { get; }
|
||||
string Name { get; }
|
||||
string FullName { get; }
|
||||
int TestCaseCount { get; }
|
||||
bool HasChildren { get; }
|
||||
bool IsSuite { get; }
|
||||
IEnumerable<ITestAdaptor> Children { get; }
|
||||
int TestCaseTimeout { get; }
|
||||
ITypeInfo TypeInfo { get; }
|
||||
IMethodInfo Method { get; }
|
||||
string[] Categories { get; }
|
||||
bool IsTestAssembly { get; }
|
||||
RunState RunState { get; }
|
||||
string Description { get; }
|
||||
string SkipReason { get; }
|
||||
string ParentId { get; }
|
||||
string UniqueName { get; }
|
||||
string ParentUniqueName { get; }
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 85dd7af03f02aea4aae13a3945e3b313
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,16 @@
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework.Interfaces;
|
||||
using UnityEngine.TestRunner.TestLaunchers;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner.Api
|
||||
{
|
||||
internal interface ITestAdaptorFactory
|
||||
{
|
||||
ITestAdaptor Create(ITest test);
|
||||
ITestAdaptor Create(RemoteTestData testData);
|
||||
ITestResultAdaptor Create(ITestResult testResult);
|
||||
ITestResultAdaptor Create(RemoteTestResultData testResult, RemoteTestResultDataWithTestData allData);
|
||||
ITestAdaptor BuildTree(RemoteTestResultDataWithTestData data);
|
||||
IEnumerator<ITestAdaptor> BuildTreeAsync(RemoteTestResultDataWithTestData data);
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 803abab0f7e17044db56f8760186dbd1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,86 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework.Interfaces;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner.Api
|
||||
{
|
||||
internal interface ITestResultAdaptor
|
||||
{
|
||||
ITestAdaptor Test { get; }
|
||||
string Name { get; }
|
||||
|
||||
/// <summary>Gets the full name of the test result</summary>
|
||||
string FullName { get; }
|
||||
|
||||
string ResultState { get; }
|
||||
|
||||
TestStatus TestStatus { get; }
|
||||
|
||||
/// <summary>Gets the elapsed time for running the test in seconds</summary>
|
||||
double Duration { get; }
|
||||
|
||||
/// <summary>Gets or sets the time the test started running.</summary>
|
||||
DateTime StartTime { get; }
|
||||
|
||||
/// <summary>Gets or sets the time the test finished running.</summary>
|
||||
DateTime EndTime { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the message associated with a test
|
||||
/// failure or with not running the test
|
||||
/// </summary>
|
||||
string Message { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets any stacktrace associated with an
|
||||
/// error or failure. Not available in
|
||||
/// the Compact Framework 1.0.
|
||||
/// </summary>
|
||||
string StackTrace { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of asserts executed
|
||||
/// when running the test and all its children.
|
||||
/// </summary>
|
||||
int AssertCount { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of test cases that failed
|
||||
/// when running the test and all its children.
|
||||
/// </summary>
|
||||
int FailCount { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of test cases that passed
|
||||
/// when running the test and all its children.
|
||||
/// </summary>
|
||||
int PassCount { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of test cases that were skipped
|
||||
/// when running the test and all its children.
|
||||
/// </summary>
|
||||
int SkipCount { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of test cases that were inconclusive
|
||||
/// when running the test and all its children.
|
||||
/// </summary>
|
||||
int InconclusiveCount { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether this result has any child results.
|
||||
/// Accessing HasChildren should not force creation of the
|
||||
/// Children collection in classes implementing this interface.
|
||||
/// </summary>
|
||||
bool HasChildren { get; }
|
||||
|
||||
/// <summary>Gets the the collection of child results.</summary>
|
||||
IEnumerable<ITestResultAdaptor> Children { get; }
|
||||
|
||||
/// <summary>Gets any text output written to this result.</summary>
|
||||
string Output { get; }
|
||||
|
||||
TNode ToXml();
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4f90cfe4bf5cfb44f84a5b11387f2a42
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,9 @@
|
||||
using System;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner.Api
|
||||
{
|
||||
internal interface ITestRunSettings : IDisposable
|
||||
{
|
||||
void Apply();
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2ae2ce6274819484fa8747a28cebdf3a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner.Api
|
||||
{
|
||||
interface ITestRunnerApi
|
||||
{
|
||||
void Execute(ExecutionSettings executionSettings);
|
||||
void RegisterCallbacks<T>(T testCallbacks, int priority = 0) where T : ICallbacks;
|
||||
void UnregisterCallbacks<T>(T testCallbacks) where T : ICallbacks;
|
||||
void RetrieveTestList(ExecutionSettings executionSettings, Action<ITestAdaptor> callback);
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a7842a837a4b13e41ae16193db753418
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,11 @@
|
||||
namespace UnityEditor.TestTools.TestRunner.Api
|
||||
{
|
||||
internal enum RunState
|
||||
{
|
||||
NotRunnable,
|
||||
Runnable,
|
||||
Explicit,
|
||||
Skipped,
|
||||
Ignored,
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8bb59cb2f66d156418ca1bd1e2703233
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,123 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NUnit.Framework.Interfaces;
|
||||
using NUnit.Framework.Internal;
|
||||
using UnityEngine.TestRunner.NUnitExtensions;
|
||||
using UnityEngine.TestRunner.NUnitExtensions.Runner;
|
||||
using UnityEngine.TestRunner.TestLaunchers;
|
||||
using UnityEngine.TestTools.Utils;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner.Api
|
||||
{
|
||||
internal class TestAdaptor : ITestAdaptor
|
||||
{
|
||||
internal TestAdaptor(ITest test) : this(test, new ITest[0])
|
||||
{
|
||||
}
|
||||
|
||||
internal TestAdaptor(ITest test, ITest[] additionalChildren)
|
||||
{
|
||||
Id = test.Id;
|
||||
Name = test.Name;
|
||||
var childIndex = -1;
|
||||
if (test.Properties["childIndex"].Count > 0)
|
||||
{
|
||||
childIndex = (int)test.Properties["childIndex"][0];
|
||||
}
|
||||
FullName = childIndex != -1 ? GetIndexedTestCaseName(test.FullName, childIndex) : test.FullName;
|
||||
TestCaseCount = test.TestCaseCount;
|
||||
HasChildren = test.HasChildren;
|
||||
IsSuite = test.IsSuite;
|
||||
Children = new[] {test.Tests, additionalChildren}.SelectMany(t => t).Select(t => new TestAdaptor(t)).ToArray();
|
||||
if (UnityTestExecutionContext.CurrentContext != null)
|
||||
{
|
||||
TestCaseTimeout = UnityTestExecutionContext.CurrentContext.TestCaseTimeout;
|
||||
}
|
||||
else
|
||||
{
|
||||
TestCaseTimeout = CoroutineRunner.k_DefaultTimeout;
|
||||
}
|
||||
|
||||
TypeInfo = test.TypeInfo;
|
||||
Method = test.Method;
|
||||
FullPath = GetFullPath(test);
|
||||
Categories = test.GetAllCategoriesFromTest().Distinct().ToArray();
|
||||
IsTestAssembly = test is TestAssembly;
|
||||
RunState = (RunState)Enum.Parse(typeof(RunState), test.RunState.ToString());
|
||||
Description = (string)test.Properties.Get(PropertyNames.Description);
|
||||
SkipReason = test.GetSkipReason();
|
||||
ParentId = test.GetParentId();
|
||||
UniqueName = test.GetUniqueName();
|
||||
ParentUniqueName = test.GetParentUniqueName();
|
||||
}
|
||||
|
||||
internal TestAdaptor(RemoteTestData test)
|
||||
{
|
||||
Id = test.id;
|
||||
Name = test.name;
|
||||
FullName = test.ChildIndex != -1 ? GetIndexedTestCaseName(test.fullName, test.ChildIndex) : test.fullName;
|
||||
TestCaseCount = test.testCaseCount;
|
||||
HasChildren = test.hasChildren;
|
||||
IsSuite = test.isSuite;
|
||||
m_ChildrenIds = test.childrenIds;
|
||||
TestCaseTimeout = test.testCaseTimeout;
|
||||
Categories = test.Categories;
|
||||
IsTestAssembly = test.IsTestAssembly;
|
||||
RunState = (RunState)Enum.Parse(typeof(RunState), test.RunState.ToString());
|
||||
Description = test.Description;
|
||||
SkipReason = test.SkipReason;
|
||||
ParentId = test.ParentId;
|
||||
UniqueName = test.UniqueName;
|
||||
ParentUniqueName = test.ParentUniqueName;
|
||||
}
|
||||
|
||||
internal void ApplyChildren(IEnumerable<TestAdaptor> allTests)
|
||||
{
|
||||
Children = m_ChildrenIds.Select(id => allTests.First(t => t.Id == id)).ToArray();
|
||||
}
|
||||
|
||||
public string Id { get; private set; }
|
||||
public string Name { get; private set; }
|
||||
public string FullName { get; private set; }
|
||||
public int TestCaseCount { get; private set; }
|
||||
public bool HasChildren { get; private set; }
|
||||
public bool IsSuite { get; private set; }
|
||||
public IEnumerable<ITestAdaptor> Children { get; private set; }
|
||||
public int TestCaseTimeout { get; private set; }
|
||||
public ITypeInfo TypeInfo { get; private set; }
|
||||
public IMethodInfo Method { get; private set; }
|
||||
public string FullPath { get; private set; }
|
||||
private string[] m_ChildrenIds;
|
||||
public string[] Categories { get; private set; }
|
||||
public bool IsTestAssembly { get; private set; }
|
||||
public RunState RunState { get; }
|
||||
public string Description { get; }
|
||||
public string SkipReason { get; }
|
||||
public string ParentId { get; }
|
||||
public string UniqueName { get; }
|
||||
public string ParentUniqueName { get; }
|
||||
|
||||
private static string GetFullPath(ITest test)
|
||||
{
|
||||
if (test.Parent != null && test.Parent.Parent != null)
|
||||
return GetFullPath(test.Parent) + "/" + test.Name;
|
||||
return test.Name;
|
||||
}
|
||||
|
||||
private static string GetIndexedTestCaseName(string fullName, int index)
|
||||
{
|
||||
var generatedTestSuffix = " GeneratedTestCase" + index;
|
||||
if (fullName.EndsWith(")"))
|
||||
{
|
||||
// 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)
|
||||
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
|
||||
// We just append a suffix at the end of the name in that case
|
||||
return fullName + generatedTestSuffix;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6e0e62db88935c74288c97c907243bd0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,59 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NUnit.Framework.Interfaces;
|
||||
using UnityEngine.TestRunner.TestLaunchers;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner.Api
|
||||
{
|
||||
internal class TestAdaptorFactory : ITestAdaptorFactory
|
||||
{
|
||||
public ITestAdaptor Create(ITest test)
|
||||
{
|
||||
return new TestAdaptor(test);
|
||||
}
|
||||
|
||||
public ITestAdaptor Create(RemoteTestData testData)
|
||||
{
|
||||
return new TestAdaptor(testData);
|
||||
}
|
||||
|
||||
public ITestResultAdaptor Create(ITestResult testResult)
|
||||
{
|
||||
return new TestResultAdaptor(testResult);
|
||||
}
|
||||
|
||||
public ITestResultAdaptor Create(RemoteTestResultData testResult, RemoteTestResultDataWithTestData allData)
|
||||
{
|
||||
return new TestResultAdaptor(testResult, allData);
|
||||
}
|
||||
|
||||
public ITestAdaptor BuildTree(RemoteTestResultDataWithTestData data)
|
||||
{
|
||||
var tests = data.tests.Select(remoteTestData => new TestAdaptor(remoteTestData)).ToList();
|
||||
|
||||
foreach (var test in tests)
|
||||
{
|
||||
test.ApplyChildren(tests);
|
||||
}
|
||||
|
||||
return tests.First();
|
||||
}
|
||||
|
||||
public IEnumerator<ITestAdaptor> BuildTreeAsync(RemoteTestResultDataWithTestData data)
|
||||
{
|
||||
var tests = data.tests.Select(remoteTestData => new TestAdaptor(remoteTestData)).ToList();
|
||||
|
||||
for (var index = 0; index < tests.Count; index++)
|
||||
{
|
||||
var test = tests[index];
|
||||
test.ApplyChildren(tests);
|
||||
if (index % 100 == 0)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
|
||||
yield return tests.First();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d0663d520c26b7c48a4135599e66acf8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using UnityEngine.TestTools;
|
||||
using UnityEngine.TestTools.TestRunner;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner.Api
|
||||
{
|
||||
internal class TestLauncherFactory
|
||||
{
|
||||
internal TestLauncherBase GetLauncher(ExecutionSettings executionSettings)
|
||||
{
|
||||
if (executionSettings.filter.testMode == TestMode.EditMode)
|
||||
{
|
||||
return GetEditModeLauncher(executionSettings.filter);
|
||||
}
|
||||
else
|
||||
{
|
||||
var settings = PlaymodeTestsControllerSettings.CreateRunnerSettings(executionSettings.filter.ToTestRunnerFilter());
|
||||
return GetPlayModeLauncher(settings, executionSettings);
|
||||
}
|
||||
}
|
||||
|
||||
static TestLauncherBase GetEditModeLauncher(Filter filter)
|
||||
{
|
||||
return GetEditModeLauncherForProvidedAssemblies(filter);
|
||||
}
|
||||
|
||||
static TestLauncherBase GetPlayModeLauncher(PlaymodeTestsControllerSettings settings, ExecutionSettings executionSettings)
|
||||
{
|
||||
if (executionSettings.targetPlatform != null)
|
||||
{
|
||||
return GetPlayerLauncher(settings, executionSettings.targetPlatform.Value, executionSettings.overloadTestRunSettings);
|
||||
}
|
||||
|
||||
if (PlayerSettings.runPlayModeTestAsEditModeTest)
|
||||
{
|
||||
return GetEditModeLauncherForProvidedAssemblies(executionSettings.filter, TestPlatform.PlayMode);
|
||||
}
|
||||
|
||||
return GetPlayModeLauncher(settings);
|
||||
}
|
||||
|
||||
static TestLauncherBase GetEditModeLauncherForProvidedAssemblies(Filter filter, TestPlatform testPlatform = TestPlatform.EditMode)
|
||||
{
|
||||
return new EditModeLauncher(filter.ToTestRunnerFilter(), testPlatform);
|
||||
}
|
||||
|
||||
static TestLauncherBase GetPlayModeLauncher(PlaymodeTestsControllerSettings settings)
|
||||
{
|
||||
return new PlaymodeLauncher(settings);
|
||||
}
|
||||
|
||||
static TestLauncherBase GetPlayerLauncher(PlaymodeTestsControllerSettings settings, BuildTarget targetPlatform, ITestRunSettings overloadTestRunSettings)
|
||||
{
|
||||
return new PlayerLauncher(settings, targetPlatform, overloadTestRunSettings);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f33e570b8b9af1048b80a27e7848cb09
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,11 @@
|
||||
using System;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner.Api
|
||||
{
|
||||
[Flags]
|
||||
internal enum TestMode
|
||||
{
|
||||
EditMode = 1 << 0,
|
||||
PlayMode = 1 << 1
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cad095eccea17b741bc4cd264e7441cd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,87 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NUnit.Framework.Interfaces;
|
||||
using UnityEngine.TestRunner.TestLaunchers;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner.Api
|
||||
{
|
||||
internal class TestResultAdaptor : ITestResultAdaptor
|
||||
{
|
||||
private TNode m_Node;
|
||||
|
||||
internal TestResultAdaptor(ITestResult result)
|
||||
{
|
||||
Test = new TestAdaptor(result.Test);
|
||||
Name = result.Name;
|
||||
FullName = result.FullName;
|
||||
ResultState = result.ResultState.ToString();
|
||||
TestStatus = ParseTestStatus(result.ResultState.Status);
|
||||
Duration = result.Duration;
|
||||
StartTime = result.StartTime;
|
||||
EndTime = result.EndTime;
|
||||
Message = result.Message;
|
||||
StackTrace = result.StackTrace;
|
||||
AssertCount = result.AssertCount;
|
||||
FailCount = result.FailCount;
|
||||
PassCount = result.PassCount;
|
||||
SkipCount = result.SkipCount;
|
||||
InconclusiveCount = result.InconclusiveCount;
|
||||
HasChildren = result.HasChildren;
|
||||
Output = result.Output;
|
||||
Children = result.Children.Select(child => new TestResultAdaptor(child)).ToArray();
|
||||
m_Node = result.ToXml(true);
|
||||
}
|
||||
|
||||
internal TestResultAdaptor(RemoteTestResultData result, RemoteTestResultDataWithTestData allData)
|
||||
{
|
||||
Test = new TestAdaptor(allData.tests.First(t => t.id == result.testId));
|
||||
Name = result.name;
|
||||
FullName = result.fullName;
|
||||
ResultState = result.resultState;
|
||||
TestStatus = ParseTestStatus(result.testStatus);
|
||||
Duration = result.duration;
|
||||
StartTime = result.startTime;
|
||||
EndTime = result.endTime;
|
||||
Message = result.message;
|
||||
StackTrace = result.stackTrace;
|
||||
AssertCount = result.assertCount;
|
||||
FailCount = result.failCount;
|
||||
PassCount = result.passCount;
|
||||
SkipCount = result.skipCount;
|
||||
InconclusiveCount = result.inconclusiveCount;
|
||||
HasChildren = result.hasChildren;
|
||||
Output = result.output;
|
||||
Children = result.childrenIds.Select(childId => new TestResultAdaptor(allData.results.First(r => r.testId == childId), allData)).ToArray();
|
||||
m_Node = TNode.FromXml(result.xml);
|
||||
}
|
||||
|
||||
public ITestAdaptor Test { get; private set; }
|
||||
public string Name { get; private set; }
|
||||
public string FullName { get; private set; }
|
||||
public string ResultState { get; private set; }
|
||||
public TestStatus TestStatus { get; private set; }
|
||||
public double Duration { get; private set; }
|
||||
public DateTime StartTime { get; private set; }
|
||||
public DateTime EndTime { get; private set; }
|
||||
public string Message { get; private set; }
|
||||
public string StackTrace { get; private set; }
|
||||
public int AssertCount { get; private set; }
|
||||
public int FailCount { get; private set; }
|
||||
public int PassCount { get; private set; }
|
||||
public int SkipCount { get; private set; }
|
||||
public int InconclusiveCount { get; private set; }
|
||||
public bool HasChildren { get; private set; }
|
||||
public IEnumerable<ITestResultAdaptor> Children { get; private set; }
|
||||
public string Output { get; private set; }
|
||||
public TNode ToXml()
|
||||
{
|
||||
return m_Node;
|
||||
}
|
||||
|
||||
private static TestStatus ParseTestStatus(NUnit.Framework.Interfaces.TestStatus testStatus)
|
||||
{
|
||||
return (TestStatus)Enum.Parse(typeof(TestStatus), testStatus.ToString());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d061ada5d3169454daf54243390b5fdb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner.Api
|
||||
{
|
||||
[Serializable]
|
||||
internal class TestRunData : ScriptableSingleton<TestRunData>
|
||||
{
|
||||
[SerializeField]
|
||||
public ExecutionSettings executionSettings;
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 973b024861c5ae84f869aad614234b04
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,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;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 68993ba529ae04440916cb7c23bf3279
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,10 @@
|
||||
namespace UnityEditor.TestTools.TestRunner.Api
|
||||
{
|
||||
internal enum TestStatus
|
||||
{
|
||||
Skipped,
|
||||
Passed,
|
||||
Failed,
|
||||
Inconclusive
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9ec94545c5b00344c9bd8e691f15d799
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user