Commit af571a61 authored by BlackAngle233's avatar BlackAngle233
Browse files

212

parent 1d9b5391
using System; using System;
using NUnit.Framework.Interfaces; using NUnit.Framework.Interfaces;
using UnityEngine.Events; using UnityEngine.Events;
namespace UnityEngine.TestTools.TestRunner namespace UnityEngine.TestTools.TestRunner
{ {
internal interface ITestRunnerListener internal interface ITestRunnerListener
{ {
void RunStarted(ITest testsToRun); void RunStarted(ITest testsToRun);
void RunFinished(ITestResult testResults); void RunFinished(ITestResult testResults);
void TestStarted(ITest test); void TestStarted(ITest test);
void TestFinished(ITestResult result); void TestFinished(ITestResult result);
} }
[Serializable] [Serializable]
internal class TestFinishedEvent : UnityEvent<ITestResult> {} internal class TestFinishedEvent : UnityEvent<ITestResult> {}
[Serializable] [Serializable]
internal class TestStartedEvent : UnityEvent<ITest> {} internal class TestStartedEvent : UnityEvent<ITest> {}
[Serializable] [Serializable]
internal class RunFinishedEvent : UnityEvent<ITestResult> {} internal class RunFinishedEvent : UnityEvent<ITestResult> {}
[Serializable] [Serializable]
internal class RunStartedEvent : UnityEvent<ITest> {} internal class RunStartedEvent : UnityEvent<ITest> {}
} }
fileFormatVersion: 2 fileFormatVersion: 2
guid: d1b534518943030499685344fd1d476d guid: d1b534518943030499685344fd1d476d
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: 256a0ca37fa972840bce7fca446e75e7 guid: 256a0ca37fa972840bce7fca446e75e7
folderAsset: yes folderAsset: yes
DefaultImporter: DefaultImporter:
externalObjects: {} externalObjects: {}
userData: userData:
assetBundleName: assetBundleName:
assetBundleVariant: assetBundleVariant:
using System.Collections; using System.Collections;
namespace UnityEngine.TestTools namespace UnityEngine.TestTools
{ {
public interface IEditModeTestYieldInstruction public interface IEditModeTestYieldInstruction
{ {
bool ExpectDomainReload { get; } bool ExpectDomainReload { get; }
bool ExpectedPlaymodeState { get; } bool ExpectedPlaymodeState { get; }
IEnumerator Perform(); IEnumerator Perform();
} }
} }
fileFormatVersion: 2 fileFormatVersion: 2
guid: 898bc38486fc899428fbe5bd6adfe473 guid: 898bc38486fc899428fbe5bd6adfe473
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; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
using UnityEngine.TestRunner.NUnitExtensions; using UnityEngine.TestRunner.NUnitExtensions;
using UnityEngine.TestRunner.NUnitExtensions.Runner; using UnityEngine.TestRunner.NUnitExtensions.Runner;
using UnityEngine.TestTools.NUnitExtensions; using UnityEngine.TestTools.NUnitExtensions;
using UnityEngine.TestTools.Utils; using UnityEngine.TestTools.Utils;
namespace UnityEngine.TestTools.TestRunner namespace UnityEngine.TestTools.TestRunner
{ {
[Serializable] [Serializable]
[AddComponentMenu("")] [AddComponentMenu("")]
internal class PlaymodeTestsController : MonoBehaviour internal class PlaymodeTestsController : MonoBehaviour
{ {
private IEnumerator m_TestSteps; private IEnumerator m_TestSteps;
[SerializeField] [SerializeField]
private List<string> m_AssembliesWithTests; private List<string> m_AssembliesWithTests;
public List<string> AssembliesWithTests public List<string> AssembliesWithTests
{ {
get get
{ {
return m_AssembliesWithTests; return m_AssembliesWithTests;
} }
set set
{ {
m_AssembliesWithTests = value; m_AssembliesWithTests = value;
} }
} }
[SerializeField] [SerializeField]
internal TestStartedEvent testStartedEvent = new TestStartedEvent(); internal TestStartedEvent testStartedEvent = new TestStartedEvent();
[SerializeField] [SerializeField]
internal TestFinishedEvent testFinishedEvent = new TestFinishedEvent(); internal TestFinishedEvent testFinishedEvent = new TestFinishedEvent();
[SerializeField] [SerializeField]
internal RunStartedEvent runStartedEvent = new RunStartedEvent(); internal RunStartedEvent runStartedEvent = new RunStartedEvent();
[SerializeField] [SerializeField]
internal RunFinishedEvent runFinishedEvent = new RunFinishedEvent(); internal RunFinishedEvent runFinishedEvent = new RunFinishedEvent();
internal const string kPlaymodeTestControllerName = "Code-based tests runner"; internal const string kPlaymodeTestControllerName = "Code-based tests runner";
[SerializeField] [SerializeField]
public PlaymodeTestsControllerSettings settings = new PlaymodeTestsControllerSettings(); public PlaymodeTestsControllerSettings settings = new PlaymodeTestsControllerSettings();
internal UnityTestAssemblyRunner m_Runner; internal UnityTestAssemblyRunner m_Runner;
public IEnumerator Start() public IEnumerator Start()
{ {
//Skip 2 frame because Unity. //Skip 2 frame because Unity.
yield return null; yield return null;
yield return null; yield return null;
StartCoroutine(Run()); StartCoroutine(Run());
} }
internal static bool IsControllerOnScene() internal static bool IsControllerOnScene()
{ {
return GameObject.Find(kPlaymodeTestControllerName) != null; return GameObject.Find(kPlaymodeTestControllerName) != null;
} }
internal static PlaymodeTestsController GetController() internal static PlaymodeTestsController GetController()
{ {
return GameObject.Find(kPlaymodeTestControllerName).GetComponent<PlaymodeTestsController>(); return GameObject.Find(kPlaymodeTestControllerName).GetComponent<PlaymodeTestsController>();
} }
public IEnumerator TestRunnerCoroutine() public IEnumerator TestRunnerCoroutine()
{ {
while (m_TestSteps.MoveNext()) while (m_TestSteps.MoveNext())
{ {
yield return m_TestSteps.Current; yield return m_TestSteps.Current;
} }
if (m_Runner.IsTestComplete) if (m_Runner.IsTestComplete)
{ {
runFinishedEvent.Invoke(m_Runner.Result); runFinishedEvent.Invoke(m_Runner.Result);
Cleanup(); Cleanup();
yield return null; yield return null;
} }
} }
public IEnumerator Run() public IEnumerator Run()
{ {
CoroutineTestWorkItem.monoBehaviourCoroutineRunner = this; CoroutineTestWorkItem.monoBehaviourCoroutineRunner = this;
gameObject.hideFlags |= HideFlags.DontSave; gameObject.hideFlags |= HideFlags.DontSave;
if (settings.sceneBased) if (settings.sceneBased)
{ {
SceneManager.LoadScene(1, LoadSceneMode.Additive); SceneManager.LoadScene(1, LoadSceneMode.Additive);
yield return null; yield return null;
} }
var testListUtil = new PlayerTestAssemblyProvider(new AssemblyLoadProxy(), m_AssembliesWithTests); var testListUtil = new PlayerTestAssemblyProvider(new AssemblyLoadProxy(), m_AssembliesWithTests);
m_Runner = new UnityTestAssemblyRunner(new UnityTestAssemblyBuilder(), new PlaymodeWorkItemFactory()); m_Runner = new UnityTestAssemblyRunner(new UnityTestAssemblyBuilder(), new PlaymodeWorkItemFactory());
var loadedTests = m_Runner.Load(testListUtil.GetUserAssemblies().Select(a => a.Assembly).ToArray(), TestPlatform.PlayMode, UnityTestAssemblyBuilder.GetNUnitTestBuilderSettings(TestPlatform.PlayMode)); var loadedTests = m_Runner.Load(testListUtil.GetUserAssemblies().Select(a => a.Assembly).ToArray(), TestPlatform.PlayMode, UnityTestAssemblyBuilder.GetNUnitTestBuilderSettings(TestPlatform.PlayMode));
loadedTests.ParseForNameDuplicates(); loadedTests.ParseForNameDuplicates();
runStartedEvent.Invoke(m_Runner.LoadedTest); runStartedEvent.Invoke(m_Runner.LoadedTest);
var testListenerWrapper = new TestListenerWrapper(testStartedEvent, testFinishedEvent); var testListenerWrapper = new TestListenerWrapper(testStartedEvent, testFinishedEvent);
m_TestSteps = m_Runner.Run(testListenerWrapper, settings.BuildNUnitFilter()).GetEnumerator(); m_TestSteps = m_Runner.Run(testListenerWrapper, settings.BuildNUnitFilter()).GetEnumerator();
yield return TestRunnerCoroutine(); yield return TestRunnerCoroutine();
} }
public void Cleanup() public void Cleanup()
{ {
if (m_Runner != null) if (m_Runner != null)
{ {
m_Runner.StopRun(); m_Runner.StopRun();
m_Runner = null; m_Runner = null;
} }
if (Application.isEditor) if (Application.isEditor)
{ {
Destroy(gameObject); Destroy(gameObject);
} }
} }
public static void TryCleanup() public static void TryCleanup()
{ {
var controller = GetController(); var controller = GetController();
if (controller != null) if (controller != null)
{ {
controller.Cleanup(); controller.Cleanup();
} }
} }
} }
} }
fileFormatVersion: 2 fileFormatVersion: 2
guid: 102e512f651ee834f951a2516c1ea3b8 guid: 102e512f651ee834f951a2516c1ea3b8
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 NUnit.Framework.Interfaces; using NUnit.Framework.Interfaces;
using NUnit.Framework.Internal.Filters; using NUnit.Framework.Internal.Filters;
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
using UnityEngine.TestTools.TestRunner.GUI; using UnityEngine.TestTools.TestRunner.GUI;
namespace UnityEngine.TestTools.TestRunner namespace UnityEngine.TestTools.TestRunner
{ {
[Serializable] [Serializable]
internal class PlaymodeTestsControllerSettings internal class PlaymodeTestsControllerSettings
{ {
[SerializeField] [SerializeField]
public TestRunnerFilter[] filters; public TestRunnerFilter[] filters;
public bool sceneBased; public bool sceneBased;
public string originalScene; public string originalScene;
public string bootstrapScene; public string bootstrapScene;
public static PlaymodeTestsControllerSettings CreateRunnerSettings(TestRunnerFilter[] filters) public static PlaymodeTestsControllerSettings CreateRunnerSettings(TestRunnerFilter[] filters)
{ {
var settings = new PlaymodeTestsControllerSettings var settings = new PlaymodeTestsControllerSettings
{ {
filters = filters, filters = filters,
sceneBased = false, sceneBased = false,
originalScene = SceneManager.GetActiveScene().path, originalScene = SceneManager.GetActiveScene().path,
bootstrapScene = null bootstrapScene = null
}; };
return settings; return settings;
} }
internal ITestFilter BuildNUnitFilter() internal ITestFilter BuildNUnitFilter()
{ {
return new OrFilter(filters.Select(f => f.BuildNUnitFilter()).ToArray()); return new OrFilter(filters.Select(f => f.BuildNUnitFilter()).ToArray());
} }
} }
} }
fileFormatVersion: 2 fileFormatVersion: 2
guid: 2799eb4c84e72e54092a292cf626936b guid: 2799eb4c84e72e54092a292cf626936b
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: 91c20d2c22b8b3a4cb6c816bd225591a guid: 91c20d2c22b8b3a4cb6c816bd225591a
folderAsset: yes folderAsset: yes
DefaultImporter: DefaultImporter:
externalObjects: {} externalObjects: {}
userData: userData:
assetBundleName: assetBundleName:
assetBundleVariant: assetBundleVariant:
using System; using System;
using NUnit.Framework.Interfaces; using NUnit.Framework.Interfaces;
namespace UnityEngine.TestRunner.TestLaunchers namespace UnityEngine.TestRunner.TestLaunchers
{ {
internal interface IRemoteTestResultDataFactory internal interface IRemoteTestResultDataFactory
{ {
RemoteTestResultDataWithTestData CreateFromTestResult(ITestResult result); RemoteTestResultDataWithTestData CreateFromTestResult(ITestResult result);
RemoteTestResultDataWithTestData CreateFromTest(ITest test); RemoteTestResultDataWithTestData CreateFromTest(ITest test);
} }
} }
fileFormatVersion: 2 fileFormatVersion: 2
guid: 874c0713cdc44f549b0161750b48d2c2 guid: 874c0713cdc44f549b0161750b48d2c2
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 UnityEngine.TestRunner.TestLaunchers namespace UnityEngine.TestRunner.TestLaunchers
{ {
internal static class PlayerConnectionMessageIds internal static class PlayerConnectionMessageIds
{ {
public static Guid runStartedMessageId { get { return new Guid("6a7f53dd-4672-461d-a7b5-9467e9393fd3"); } } public static Guid runStartedMessageId { get { return new Guid("6a7f53dd-4672-461d-a7b5-9467e9393fd3"); } }
public static Guid runFinishedMessageId { get { return new Guid("ffb622fc-34ad-4901-8d7b-47fb04b0bdd4"); } } public static Guid runFinishedMessageId { get { return new Guid("ffb622fc-34ad-4901-8d7b-47fb04b0bdd4"); } }
public static Guid testStartedMessageId { get { return new Guid("b54d241e-d88d-4dba-8c8f-ee415d11c030"); } } public static Guid testStartedMessageId { get { return new Guid("b54d241e-d88d-4dba-8c8f-ee415d11c030"); } }
public static Guid testFinishedMessageId { get { return new Guid("72f7b7f4-6829-4cd1-afde-78872b9d5adc"); } } public static Guid testFinishedMessageId { get { return new Guid("72f7b7f4-6829-4cd1-afde-78872b9d5adc"); } }
public static Guid quitPlayerMessageId { get { return new Guid("ab44bfe0-bb50-4ee6-9977-69d2ea6bb3a0"); } } public static Guid quitPlayerMessageId { get { return new Guid("ab44bfe0-bb50-4ee6-9977-69d2ea6bb3a0"); } }
public static Guid playerAliveHeartbeat { get { return new Guid("8c0c307b-f7fd-4216-8623-35b4b3f55fb6"); } } public static Guid playerAliveHeartbeat { get { return new Guid("8c0c307b-f7fd-4216-8623-35b4b3f55fb6"); } }
} }
} }
fileFormatVersion: 2 fileFormatVersion: 2
guid: 41d60936b62cc6d4ca7fe628b22b0e40 guid: 41d60936b62cc6d4ca7fe628b22b0e40
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 NUnit.Framework.Interfaces; using NUnit.Framework.Interfaces;
using NUnit.Framework.Internal; using NUnit.Framework.Internal;
using UnityEngine.TestRunner.NUnitExtensions; using UnityEngine.TestRunner.NUnitExtensions;
namespace UnityEngine.TestRunner.TestLaunchers namespace UnityEngine.TestRunner.TestLaunchers
{ {
[Serializable] [Serializable]
internal class RemoteTestData internal class RemoteTestData
{ {
public string id; public string id;
public string name; public string name;
public string fullName; public string fullName;
public int testCaseCount; public int testCaseCount;
public int ChildIndex; public int ChildIndex;
public bool hasChildren; public bool hasChildren;
public bool isSuite; public bool isSuite;
public string[] childrenIds; public string[] childrenIds;
public int testCaseTimeout; public int testCaseTimeout;
public string[] Categories; public string[] Categories;
public bool IsTestAssembly; public bool IsTestAssembly;
public RunState RunState; public RunState RunState;
public string Description; public string Description;
public string SkipReason; public string SkipReason;
public string ParentId; public string ParentId;
public string UniqueName; public string UniqueName;
public string ParentUniqueName; public string ParentUniqueName;
public string ParentFullName; public string ParentFullName;
internal RemoteTestData(ITest test) internal RemoteTestData(ITest test)
{ {
id = test.Id; id = test.Id;
name = test.Name; name = test.Name;
fullName = test.FullName; fullName = test.FullName;
testCaseCount = test.TestCaseCount; testCaseCount = test.TestCaseCount;
ChildIndex = -1; 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];
} }
hasChildren = test.HasChildren; hasChildren = test.HasChildren;
isSuite = test.IsSuite; isSuite = test.IsSuite;
childrenIds = test.Tests.Select(t => t.Id).ToArray(); childrenIds = test.Tests.Select(t => t.Id).ToArray();
Categories = test.GetAllCategoriesFromTest().ToArray(); Categories = test.GetAllCategoriesFromTest().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();
UniqueName = test.GetUniqueName(); UniqueName = test.GetUniqueName();
ParentUniqueName = test.GetParentUniqueName(); ParentUniqueName = test.GetParentUniqueName();
ParentFullName = test.GetParentFullName(); ParentFullName = test.GetParentFullName();
} }
} }
} }
fileFormatVersion: 2 fileFormatVersion: 2
guid: b135ec222fdcd11468014c90d11d6821 guid: b135ec222fdcd11468014c90d11d6821
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:
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