initial project folder
This commit is contained in:
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5d7f0d6acfced954682a89e7002c04d9
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,190 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using NUnit.Framework.Interfaces;
|
||||
using NUnit.Framework.Internal;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools.TestRunner;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner
|
||||
{
|
||||
internal class EditModeRunnerCallback : ScriptableObject, ITestRunnerListener
|
||||
{
|
||||
private EditModeLauncherContextSettings m_Settings;
|
||||
public SceneSetup[] previousSceneSetup;
|
||||
public int undoGroup;
|
||||
public EditModeRunner runner;
|
||||
|
||||
private bool m_Canceled;
|
||||
private ITest m_CurrentTest;
|
||||
private int m_TotalTests;
|
||||
|
||||
[SerializeField]
|
||||
private List<string> m_PendingTests;
|
||||
[SerializeField]
|
||||
private string m_LastCountedTestName;
|
||||
[SerializeField]
|
||||
private bool m_RunRestarted;
|
||||
|
||||
public void OnDestroy()
|
||||
{
|
||||
CleanUp();
|
||||
}
|
||||
|
||||
public void RunStarted(ITest testsToRun)
|
||||
{
|
||||
Setup();
|
||||
if (m_PendingTests == null)
|
||||
{
|
||||
m_PendingTests = GetTestsExpectedToRun(testsToRun, runner.GetFilter());
|
||||
m_TotalTests = m_PendingTests.Count;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnEnable()
|
||||
{
|
||||
if (m_RunRestarted)
|
||||
{
|
||||
Setup();
|
||||
}
|
||||
}
|
||||
|
||||
private void Setup()
|
||||
{
|
||||
m_Settings = new EditModeLauncherContextSettings();
|
||||
Application.logMessageReceivedThreaded += LogReceived;
|
||||
EditorApplication.playModeStateChanged += WaitForExitPlaymode;
|
||||
EditorApplication.update += DisplayProgressBar;
|
||||
AssemblyReloadEvents.beforeAssemblyReload += BeforeAssemblyReload;
|
||||
}
|
||||
|
||||
private void BeforeAssemblyReload()
|
||||
{
|
||||
if (m_CurrentTest != null)
|
||||
{
|
||||
m_LastCountedTestName = m_CurrentTest.FullName;
|
||||
m_RunRestarted = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void DisplayProgressBar()
|
||||
{
|
||||
if (m_CurrentTest == null)
|
||||
return;
|
||||
if (!m_Canceled && EditorUtility.DisplayCancelableProgressBar("Test Runner", "Running test " + m_CurrentTest.Name, Math.Min(1.0f, (float)(m_TotalTests - m_PendingTests.Count) / m_TotalTests)))
|
||||
{
|
||||
EditorApplication.update -= DisplayProgressBar;
|
||||
m_Canceled = true;
|
||||
EditorUtility.ClearProgressBar();
|
||||
runner.OnRunCancel();
|
||||
}
|
||||
}
|
||||
|
||||
private static void LogReceived(string message, string stacktrace, LogType type)
|
||||
{
|
||||
if (TestContext.Out != null)
|
||||
TestContext.Out.WriteLine(message);
|
||||
}
|
||||
|
||||
private static void WaitForExitPlaymode(PlayModeStateChange state)
|
||||
{
|
||||
if (state == PlayModeStateChange.EnteredEditMode)
|
||||
{
|
||||
EditorApplication.playModeStateChanged -= WaitForExitPlaymode;
|
||||
//because logMessage is reset on Enter EditMode
|
||||
//we remove and add the callback
|
||||
//because Unity
|
||||
Application.logMessageReceivedThreaded -= LogReceived;
|
||||
Application.logMessageReceivedThreaded += LogReceived;
|
||||
}
|
||||
}
|
||||
|
||||
public void RunFinished(ITestResult result)
|
||||
{
|
||||
if (previousSceneSetup != null && previousSceneSetup.Length > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
EditorSceneManager.RestoreSceneManagerSetup(previousSceneSetup);
|
||||
}
|
||||
catch (ArgumentException e)
|
||||
{
|
||||
Debug.LogWarning(e.Message);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects, NewSceneMode.Single);
|
||||
}
|
||||
CleanUp();
|
||||
PerformUndo(undoGroup);
|
||||
}
|
||||
|
||||
private void CleanUp()
|
||||
{
|
||||
m_CurrentTest = null;
|
||||
EditorUtility.ClearProgressBar();
|
||||
if (m_Settings != null)
|
||||
{
|
||||
m_Settings.Dispose();
|
||||
}
|
||||
Application.logMessageReceivedThreaded -= LogReceived;
|
||||
EditorApplication.update -= DisplayProgressBar;
|
||||
}
|
||||
|
||||
public void TestStarted(ITest test)
|
||||
{
|
||||
if (test.IsSuite || !(test is TestMethod))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_CurrentTest = test;
|
||||
|
||||
if (m_RunRestarted)
|
||||
{
|
||||
if (test.FullName == m_LastCountedTestName)
|
||||
m_RunRestarted = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void TestFinished(ITestResult result)
|
||||
{
|
||||
if (result.Test is TestMethod)
|
||||
{
|
||||
m_PendingTests.Remove(result.Test.FullName);
|
||||
}
|
||||
}
|
||||
|
||||
private static void PerformUndo(int undoGroup)
|
||||
{
|
||||
EditorUtility.DisplayProgressBar("Undo", "Reverting changes to the scene", 0);
|
||||
var undoStartTime = DateTime.Now;
|
||||
Undo.RevertAllDownToGroup(undoGroup);
|
||||
if ((DateTime.Now - undoStartTime).TotalSeconds > 1)
|
||||
Debug.LogWarning("Undo after editor test run took " + (DateTime.Now - undoStartTime).Seconds + " seconds.");
|
||||
EditorUtility.ClearProgressBar();
|
||||
}
|
||||
|
||||
private static List<string> GetTestsExpectedToRun(ITest test, ITestFilter filter)
|
||||
{
|
||||
var expectedTests = new List<string>();
|
||||
|
||||
if (filter.Pass(test))
|
||||
{
|
||||
if (test.IsSuite)
|
||||
{
|
||||
expectedTests.AddRange(test.Tests.SelectMany(subTest => GetTestsExpectedToRun(subTest, filter)));
|
||||
}
|
||||
else
|
||||
{
|
||||
expectedTests.Add(test.FullName);
|
||||
}
|
||||
}
|
||||
|
||||
return expectedTests;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cc456ba93311a3a43ad896449fee9868
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,83 @@
|
||||
using UnityEditor.TestTools.TestRunner.Api;
|
||||
using UnityEditor.TestTools.TestRunner.CommandLineTest;
|
||||
using UnityEngine.TestTools.TestRunner.GUI;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner
|
||||
{
|
||||
internal class RerunCallback : ScriptableObject, ICallbacks
|
||||
{
|
||||
public static bool useMockRunFilter = false;
|
||||
public static TestRunnerFilter mockRunFilter = null;
|
||||
|
||||
public void RunFinished(ITestResultAdaptor result)
|
||||
{
|
||||
if (RerunCallbackData.instance.runFilter == null)
|
||||
RerunCallbackData.instance.runFilter = new TestRunnerFilter();
|
||||
|
||||
var runFilter = RerunCallbackData.instance.runFilter;
|
||||
|
||||
if (useMockRunFilter)
|
||||
{
|
||||
runFilter = mockRunFilter;
|
||||
}
|
||||
|
||||
runFilter.testRepetitions--;
|
||||
if (runFilter.testRepetitions <= 0 || result.TestStatus != TestStatus.Passed)
|
||||
{
|
||||
ExitCallbacks.preventExit = false;
|
||||
return;
|
||||
}
|
||||
|
||||
ExitCallbacks.preventExit = true;
|
||||
if (EditorApplication.isPlaying)
|
||||
{
|
||||
EditorApplication.playModeStateChanged += WaitForExitPlaymode;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!useMockRunFilter)
|
||||
{
|
||||
ExecuteTestRunnerAPI();
|
||||
}
|
||||
}
|
||||
|
||||
private static void WaitForExitPlaymode(PlayModeStateChange state)
|
||||
{
|
||||
if (state == PlayModeStateChange.EnteredEditMode)
|
||||
{
|
||||
ExecuteTestRunnerAPI();
|
||||
}
|
||||
}
|
||||
|
||||
private static void ExecuteTestRunnerAPI()
|
||||
{
|
||||
var runFilter = RerunCallbackData.instance.runFilter;
|
||||
var testMode = RerunCallbackData.instance.testMode;
|
||||
|
||||
var testRunnerApi = ScriptableObject.CreateInstance<TestRunnerApi>();
|
||||
testRunnerApi.Execute(new Api.ExecutionSettings()
|
||||
{
|
||||
filter = new Filter()
|
||||
{
|
||||
categoryNames = runFilter.categoryNames,
|
||||
groupNames = runFilter.groupNames,
|
||||
testMode = testMode,
|
||||
testNames = runFilter.testNames
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void TestStarted(ITestAdaptor test)
|
||||
{
|
||||
}
|
||||
|
||||
public void TestFinished(ITestResultAdaptor result)
|
||||
{
|
||||
}
|
||||
|
||||
public void RunStarted(ITestAdaptor testsToRun)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b7ff2b2e91321ff4381d4ab45870a32e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,15 @@
|
||||
using UnityEditor.TestTools.TestRunner.Api;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools.TestRunner.GUI;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner
|
||||
{
|
||||
internal class RerunCallbackData : ScriptableSingleton<RerunCallbackData>
|
||||
{
|
||||
[SerializeField]
|
||||
internal TestRunnerFilter runFilter;
|
||||
|
||||
[SerializeField]
|
||||
internal TestMode testMode;
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 087cba9fa6ac867479a0b0fdc0a5864b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,17 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor.TestTools.TestRunner.Api;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner
|
||||
{
|
||||
[InitializeOnLoad]
|
||||
static class RerunCallbackInitializer
|
||||
{
|
||||
static RerunCallbackInitializer()
|
||||
{
|
||||
var testRunnerApi = ScriptableObject.CreateInstance<TestRunnerApi>();
|
||||
|
||||
var rerunCallback = ScriptableObject.CreateInstance<RerunCallback>();
|
||||
testRunnerApi.RegisterCallbacks<RerunCallback>(rerunCallback);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f73fc901e4b0f2d4daf11f46506054ba
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,37 @@
|
||||
using NUnit.Framework.Interfaces;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools.TestRunner;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner
|
||||
{
|
||||
internal class TestRunnerCallback : ScriptableObject, ITestRunnerListener
|
||||
{
|
||||
public void RunStarted(ITest testsToRun)
|
||||
{
|
||||
EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
|
||||
}
|
||||
|
||||
private void OnPlayModeStateChanged(PlayModeStateChange state)
|
||||
{
|
||||
if (state == PlayModeStateChange.ExitingPlayMode)
|
||||
{
|
||||
EditorApplication.playModeStateChanged -= OnPlayModeStateChanged;
|
||||
//We need to make sure we don't block NUnit thread in case we exit PlayMode earlier
|
||||
PlaymodeTestsController.TryCleanup();
|
||||
}
|
||||
}
|
||||
|
||||
public void RunFinished(ITestResult testResults)
|
||||
{
|
||||
EditorApplication.isPlaying = false;
|
||||
}
|
||||
|
||||
public void TestStarted(ITest testName)
|
||||
{
|
||||
}
|
||||
|
||||
public void TestFinished(ITestResult test)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d44e6804bc58be84ea71a619b468f150
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,32 @@
|
||||
using UnityEditor.TestTools.TestRunner.Api;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner.GUI
|
||||
{
|
||||
internal class WindowResultUpdater : ICallbacks
|
||||
{
|
||||
public void RunStarted(ITestAdaptor testsToRun)
|
||||
{
|
||||
}
|
||||
|
||||
public void RunFinished(ITestResultAdaptor testResults)
|
||||
{
|
||||
if (TestRunnerWindow.s_Instance != null)
|
||||
{
|
||||
TestRunnerWindow.s_Instance.RebuildUIFilter();
|
||||
}
|
||||
}
|
||||
|
||||
public void TestStarted(ITestAdaptor testName)
|
||||
{
|
||||
}
|
||||
|
||||
public void TestFinished(ITestResultAdaptor test)
|
||||
{
|
||||
if (TestRunnerWindow.s_Instance == null)
|
||||
return;
|
||||
|
||||
var result = new TestRunnerResult(test);
|
||||
TestRunnerWindow.s_Instance.m_SelectedTestTypes.UpdateResult(result);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6d468ee3657be7a43a2ef2178ec14239
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,32 @@
|
||||
using System.Collections;
|
||||
using System.Reflection;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner
|
||||
{
|
||||
internal class EditModePcHelper : TestCommandPcHelper
|
||||
{
|
||||
public override void SetEnumeratorPC(IEnumerator enumerator, int pc)
|
||||
{
|
||||
GetPCFieldInfo(enumerator).SetValue(enumerator, pc);
|
||||
}
|
||||
|
||||
public override int GetEnumeratorPC(IEnumerator enumerator)
|
||||
{
|
||||
if (enumerator == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return (int)GetPCFieldInfo(enumerator).GetValue(enumerator);
|
||||
}
|
||||
|
||||
private FieldInfo GetPCFieldInfo(IEnumerator enumerator)
|
||||
{
|
||||
var field = enumerator.GetType().GetField("$PC", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
if (field == null) // Roslyn
|
||||
field = enumerator.GetType().GetField("<>1__state", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
|
||||
return field;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6d16f2e78a356d34c9a32108929de932
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,423 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NUnit.Framework.Interfaces;
|
||||
using NUnit.Framework.Internal;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools.NUnitExtensions;
|
||||
using UnityEngine.TestTools.TestRunner;
|
||||
using UnityEngine.TestTools;
|
||||
using UnityEngine.TestTools.TestRunner.GUI;
|
||||
using UnityEditor.Callbacks;
|
||||
using UnityEngine.TestRunner.NUnitExtensions;
|
||||
using UnityEngine.TestRunner.NUnitExtensions.Runner;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner
|
||||
{
|
||||
internal interface IUnityTestAssemblyRunnerFactory
|
||||
{
|
||||
IUnityTestAssemblyRunner Create(TestPlatform testPlatform, WorkItemFactory factory);
|
||||
}
|
||||
|
||||
internal class UnityTestAssemblyRunnerFactory : IUnityTestAssemblyRunnerFactory
|
||||
{
|
||||
public IUnityTestAssemblyRunner Create(TestPlatform testPlatform, WorkItemFactory factory)
|
||||
{
|
||||
return new UnityTestAssemblyRunner(new UnityTestAssemblyBuilder(), factory);
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
internal class EditModeRunner : ScriptableObject, IDisposable
|
||||
{
|
||||
[SerializeField]
|
||||
private TestRunnerFilter m_Filter;
|
||||
|
||||
//The counter from the IEnumerator object
|
||||
[SerializeField]
|
||||
private int m_CurrentPC;
|
||||
|
||||
[SerializeField]
|
||||
private bool m_ExecuteOnEnable;
|
||||
|
||||
[SerializeField]
|
||||
private List<string> m_AlreadyStartedTests;
|
||||
|
||||
[SerializeField]
|
||||
private List<TestResultSerializer> m_ExecutedTests;
|
||||
|
||||
[SerializeField]
|
||||
private List<ScriptableObject> m_CallbackObjects = new List<ScriptableObject>();
|
||||
|
||||
[SerializeField]
|
||||
private TestStartedEvent m_TestStartedEvent = new TestStartedEvent();
|
||||
|
||||
[SerializeField]
|
||||
private TestFinishedEvent m_TestFinishedEvent = new TestFinishedEvent();
|
||||
|
||||
[SerializeField]
|
||||
private RunStartedEvent m_RunStartedEvent = new RunStartedEvent();
|
||||
|
||||
[SerializeField]
|
||||
private RunFinishedEvent m_RunFinishedEvent = new RunFinishedEvent();
|
||||
|
||||
[SerializeField]
|
||||
private TestRunnerStateSerializer m_TestRunnerStateSerializer = new TestRunnerStateSerializer();
|
||||
|
||||
[SerializeField]
|
||||
private TestFileCleanupVerifier m_CleanupVerifier = new TestFileCleanupVerifier();
|
||||
|
||||
[SerializeField]
|
||||
private bool m_RunningTests;
|
||||
|
||||
[SerializeField]
|
||||
private TestPlatform m_TestPlatform;
|
||||
|
||||
[SerializeField]
|
||||
private object m_CurrentYieldObject;
|
||||
|
||||
[SerializeField]
|
||||
private BeforeAfterTestCommandState m_SetUpTearDownState;
|
||||
[SerializeField]
|
||||
private BeforeAfterTestCommandState m_OuterUnityTestActionState;
|
||||
|
||||
internal IUnityTestAssemblyRunner m_Runner;
|
||||
|
||||
private ConstructDelegator m_ConstructDelegator;
|
||||
|
||||
private IEnumerator m_RunStep;
|
||||
|
||||
public IUnityTestAssemblyRunnerFactory UnityTestAssemblyRunnerFactory { get; set; }
|
||||
|
||||
public void Init(TestRunnerFilter filter, TestPlatform platform)
|
||||
{
|
||||
m_Filter = filter;
|
||||
m_TestPlatform = platform;
|
||||
m_AlreadyStartedTests = new List<string>();
|
||||
m_ExecutedTests = new List<TestResultSerializer>();
|
||||
InitRunner();
|
||||
}
|
||||
|
||||
private void InitRunner()
|
||||
{
|
||||
//We give the EditMode platform here so we dont suddenly create Playmode work items in the test Runner.
|
||||
m_Runner = (UnityTestAssemblyRunnerFactory ?? new UnityTestAssemblyRunnerFactory()).Create(TestPlatform.EditMode, new EditmodeWorkItemFactory());
|
||||
var testAssemblyProvider = new EditorLoadedTestAssemblyProvider(new EditorCompilationInterfaceProxy(), new EditorAssembliesProxy());
|
||||
var loadedTests = m_Runner.Load(
|
||||
testAssemblyProvider.GetAssembliesGroupedByType(m_TestPlatform).Select(x => x.Assembly).ToArray(),
|
||||
UnityTestAssemblyBuilder.GetNUnitTestBuilderSettings(m_TestPlatform));
|
||||
loadedTests.ParseForNameDuplicates();
|
||||
hideFlags |= HideFlags.DontSave;
|
||||
EnumerableSetUpTearDownCommand.ActivePcHelper = new EditModePcHelper();
|
||||
OuterUnityTestActionCommand.ActivePcHelper = new EditModePcHelper();
|
||||
}
|
||||
|
||||
public void OnEnable()
|
||||
{
|
||||
if (m_ExecuteOnEnable)
|
||||
{
|
||||
InitRunner();
|
||||
m_ExecuteOnEnable = false;
|
||||
foreach (var callback in m_CallbackObjects)
|
||||
{
|
||||
AddListeners(callback as ITestRunnerListener);
|
||||
}
|
||||
m_ConstructDelegator = new ConstructDelegator(m_TestRunnerStateSerializer);
|
||||
|
||||
EnumeratorStepHelper.SetEnumeratorPC(m_CurrentPC);
|
||||
|
||||
UnityWorkItemDataHolder.alreadyExecutedTests = m_ExecutedTests.Select(x => x.fullName).ToList();
|
||||
UnityWorkItemDataHolder.alreadyStartedTests = m_AlreadyStartedTests;
|
||||
Run();
|
||||
}
|
||||
}
|
||||
|
||||
public void TestStartedEvent(ITest test)
|
||||
{
|
||||
m_AlreadyStartedTests.Add(test.FullName);
|
||||
}
|
||||
|
||||
public void TestFinishedEvent(ITestResult testResult)
|
||||
{
|
||||
m_AlreadyStartedTests.Remove(testResult.FullName);
|
||||
m_ExecutedTests.Add(TestResultSerializer.MakeFromTestResult(testResult));
|
||||
}
|
||||
|
||||
public void Run()
|
||||
{
|
||||
EditModeTestCallbacks.RestoringTestContext += OnRestoringTest;
|
||||
var context = m_Runner.GetCurrentContext();
|
||||
if (m_SetUpTearDownState == null)
|
||||
{
|
||||
m_SetUpTearDownState = CreateInstance<BeforeAfterTestCommandState>();
|
||||
}
|
||||
context.SetUpTearDownState = m_SetUpTearDownState;
|
||||
|
||||
if (m_OuterUnityTestActionState == null)
|
||||
{
|
||||
m_OuterUnityTestActionState = CreateInstance<BeforeAfterTestCommandState>();
|
||||
}
|
||||
context.OuterUnityTestActionState = m_OuterUnityTestActionState;
|
||||
|
||||
m_CleanupVerifier.RegisterExistingFiles();
|
||||
|
||||
if (!m_RunningTests)
|
||||
{
|
||||
m_RunStartedEvent.Invoke(m_Runner.LoadedTest);
|
||||
}
|
||||
|
||||
if (m_ConstructDelegator == null)
|
||||
m_ConstructDelegator = new ConstructDelegator(m_TestRunnerStateSerializer);
|
||||
|
||||
Reflect.ConstructorCallWrapper = m_ConstructDelegator.Delegate;
|
||||
m_TestStartedEvent.AddListener(TestStartedEvent);
|
||||
m_TestFinishedEvent.AddListener(TestFinishedEvent);
|
||||
|
||||
AssemblyReloadEvents.beforeAssemblyReload += OnBeforeAssemblyReload;
|
||||
|
||||
RunningTests = true;
|
||||
|
||||
EditorApplication.LockReloadAssemblies();
|
||||
|
||||
var testListenerWrapper = new TestListenerWrapper(m_TestStartedEvent, m_TestFinishedEvent);
|
||||
m_RunStep = m_Runner.Run(testListenerWrapper, m_Filter.BuildNUnitFilter()).GetEnumerator();
|
||||
m_RunningTests = true;
|
||||
|
||||
EditorApplication.update += TestConsumer;
|
||||
}
|
||||
|
||||
private void OnBeforeAssemblyReload()
|
||||
{
|
||||
EditorApplication.update -= TestConsumer;
|
||||
|
||||
if (m_ExecuteOnEnable)
|
||||
{
|
||||
AssemblyReloadEvents.beforeAssemblyReload -= OnBeforeAssemblyReload;
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_Runner != null && m_Runner.TopLevelWorkItem != null)
|
||||
m_Runner.TopLevelWorkItem.ResultedInDomainReload = true;
|
||||
|
||||
if (RunningTests)
|
||||
{
|
||||
Debug.LogError("TestRunner: Unexpected assembly reload happened while running tests");
|
||||
|
||||
EditorUtility.ClearProgressBar();
|
||||
|
||||
if (m_Runner.GetCurrentContext() != null && m_Runner.GetCurrentContext().CurrentResult != null)
|
||||
{
|
||||
m_Runner.GetCurrentContext().CurrentResult.SetResult(ResultState.Cancelled, "Unexpected assembly reload happened");
|
||||
}
|
||||
OnRunCancel();
|
||||
}
|
||||
}
|
||||
|
||||
private bool RunningTests;
|
||||
|
||||
private Stack<IEnumerator> StepStack = new Stack<IEnumerator>();
|
||||
|
||||
private bool MoveNextAndUpdateYieldObject()
|
||||
{
|
||||
var result = m_RunStep.MoveNext();
|
||||
|
||||
if (result)
|
||||
{
|
||||
m_CurrentYieldObject = m_RunStep.Current;
|
||||
while (m_CurrentYieldObject is IEnumerator) // going deeper
|
||||
{
|
||||
var currentEnumerator = (IEnumerator)m_CurrentYieldObject;
|
||||
|
||||
// go deeper and add parent to stack
|
||||
StepStack.Push(m_RunStep);
|
||||
|
||||
m_RunStep = currentEnumerator;
|
||||
m_CurrentYieldObject = m_RunStep.Current;
|
||||
}
|
||||
|
||||
if (StepStack.Count > 0 && m_CurrentYieldObject != null) // not null and not IEnumerator, nested
|
||||
{
|
||||
Debug.LogError("EditMode test can only yield null, but not <" + m_CurrentYieldObject.GetType().Name + ">");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (StepStack.Count == 0) // done
|
||||
return false;
|
||||
|
||||
m_RunStep = StepStack.Pop(); // going up
|
||||
return MoveNextAndUpdateYieldObject();
|
||||
}
|
||||
|
||||
private void TestConsumer()
|
||||
{
|
||||
var moveNext = MoveNextAndUpdateYieldObject();
|
||||
|
||||
if (m_CurrentYieldObject != null)
|
||||
{
|
||||
InvokeDelegator();
|
||||
}
|
||||
|
||||
if (!moveNext && !m_Runner.IsTestComplete)
|
||||
{
|
||||
CompleteTestRun();
|
||||
throw new IndexOutOfRangeException("There are no more elements to process and IsTestComplete is false");
|
||||
}
|
||||
|
||||
if (m_Runner.IsTestComplete)
|
||||
{
|
||||
CompleteTestRun();
|
||||
}
|
||||
}
|
||||
|
||||
private void CompleteTestRun()
|
||||
{
|
||||
EditorApplication.update -= TestConsumer;
|
||||
TestLauncherBase.ExecutePostBuildCleanupMethods(this.GetLoadedTests(), this.GetFilter(), Application.platform);
|
||||
m_CleanupVerifier.VerifyNoNewFilesAdded();
|
||||
m_RunFinishedEvent.Invoke(m_Runner.Result);
|
||||
|
||||
if (m_ConstructDelegator != null)
|
||||
m_ConstructDelegator.DestroyCurrentTestObjectIfExists();
|
||||
Dispose();
|
||||
UnityWorkItemDataHolder.alreadyExecutedTests = null;
|
||||
}
|
||||
|
||||
private void OnRestoringTest()
|
||||
{
|
||||
var item = m_ExecutedTests.Find(t => t.fullName == UnityTestExecutionContext.CurrentContext.CurrentTest.FullName);
|
||||
if (item != null)
|
||||
{
|
||||
item.RestoreTestResult(UnityTestExecutionContext.CurrentContext.CurrentResult);
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsCancelled()
|
||||
{
|
||||
return UnityTestExecutionContext.CurrentContext.ExecutionStatus == TestExecutionStatus.AbortRequested || UnityTestExecutionContext.CurrentContext.ExecutionStatus == TestExecutionStatus.StopRequested;
|
||||
}
|
||||
|
||||
private void InvokeDelegator()
|
||||
{
|
||||
if (m_CurrentYieldObject == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsCancelled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_CurrentYieldObject is RestoreTestContextAfterDomainReload)
|
||||
{
|
||||
if (m_TestRunnerStateSerializer.ShouldRestore())
|
||||
{
|
||||
m_TestRunnerStateSerializer.RestoreContext();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (m_CurrentYieldObject is IEditModeTestYieldInstruction)
|
||||
{
|
||||
var editModeTestYieldInstruction = (IEditModeTestYieldInstruction)m_CurrentYieldObject;
|
||||
if (editModeTestYieldInstruction.ExpectDomainReload)
|
||||
{
|
||||
PrepareForDomainReload();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
UnityTestExecutionContext.CurrentContext.CurrentResult.RecordException(e);
|
||||
return;
|
||||
}
|
||||
|
||||
Debug.LogError("EditMode test can only yield null");
|
||||
}
|
||||
|
||||
private void CompilationFailureWatch()
|
||||
{
|
||||
if (EditorApplication.isCompiling)
|
||||
return;
|
||||
|
||||
EditorApplication.update -= CompilationFailureWatch;
|
||||
|
||||
if (EditorUtility.scriptCompilationFailed)
|
||||
{
|
||||
EditorUtility.ClearProgressBar();
|
||||
OnRunCancel();
|
||||
}
|
||||
}
|
||||
|
||||
private void PrepareForDomainReload()
|
||||
{
|
||||
m_TestRunnerStateSerializer.SaveContext();
|
||||
m_CurrentPC = EnumeratorStepHelper.GetEnumeratorPC(TestEnumerator.Enumerator);
|
||||
m_ExecuteOnEnable = true;
|
||||
|
||||
RunningTests = false;
|
||||
}
|
||||
|
||||
public T AddEventHandler<T>() where T : ScriptableObject, ITestRunnerListener
|
||||
{
|
||||
var eventHandler = CreateInstance<T>();
|
||||
eventHandler.hideFlags |= HideFlags.DontSave;
|
||||
m_CallbackObjects.Add(eventHandler);
|
||||
|
||||
AddListeners(eventHandler);
|
||||
|
||||
return eventHandler;
|
||||
}
|
||||
|
||||
private void AddListeners(ITestRunnerListener eventHandler)
|
||||
{
|
||||
m_TestStartedEvent.AddListener(eventHandler.TestStarted);
|
||||
m_TestFinishedEvent.AddListener(eventHandler.TestFinished);
|
||||
m_RunStartedEvent.AddListener(eventHandler.RunStarted);
|
||||
m_RunFinishedEvent.AddListener(eventHandler.RunFinished);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Reflect.MethodCallWrapper = null;
|
||||
EditorApplication.update -= TestConsumer;
|
||||
|
||||
DestroyImmediate(this);
|
||||
|
||||
if (m_CallbackObjects != null)
|
||||
{
|
||||
foreach (var obj in m_CallbackObjects)
|
||||
{
|
||||
DestroyImmediate(obj);
|
||||
}
|
||||
m_CallbackObjects.Clear();
|
||||
}
|
||||
RunningTests = false;
|
||||
EditorApplication.UnlockReloadAssemblies();
|
||||
}
|
||||
|
||||
public void OnRunCancel()
|
||||
{
|
||||
UnityWorkItemDataHolder.alreadyExecutedTests = null;
|
||||
m_ExecuteOnEnable = false;
|
||||
m_Runner.StopRun();
|
||||
}
|
||||
|
||||
public ITest GetLoadedTests()
|
||||
{
|
||||
return m_Runner.LoadedTest;
|
||||
}
|
||||
|
||||
public ITestFilter GetFilter()
|
||||
{
|
||||
return m_Filter.BuildNUnitFilter();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c9219e99d466b7741a057132d1994f35
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,14 @@
|
||||
using NUnit.Framework.Interfaces;
|
||||
using NUnit.Framework.Internal;
|
||||
using UnityEngine.TestRunner.NUnitExtensions.Runner;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner
|
||||
{
|
||||
internal class EditmodeWorkItemFactory : WorkItemFactory
|
||||
{
|
||||
protected override UnityWorkItem Create(TestMethod method, ITestFilter filter, ITest loadedTest)
|
||||
{
|
||||
return new EditorEnumeratorTestWorkItem(method, filter);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3dde15f260b0dd1469e60d16eaa795dc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,181 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using NUnit.Framework.Interfaces;
|
||||
using NUnit.Framework.Internal;
|
||||
using NUnit.Framework.Internal.Commands;
|
||||
using NUnit.Framework.Internal.Execution;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestRunner.NUnitExtensions.Runner;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner
|
||||
{
|
||||
internal class EditorEnumeratorTestWorkItem : UnityWorkItem
|
||||
{
|
||||
private TestCommand m_Command;
|
||||
|
||||
public EditorEnumeratorTestWorkItem(TestMethod test, ITestFilter filter)
|
||||
: base(test, null)
|
||||
{
|
||||
m_Command = test.RunState == RunState.Runnable || test.RunState == RunState.Explicit && filter.IsExplicitMatch(test)
|
||||
? CommandBuilder.MakeTestCommand(test)
|
||||
: CommandBuilder.MakeSkipCommand(test);
|
||||
}
|
||||
|
||||
private static IEnumerableTestMethodCommand FindFirstIEnumerableTestMethodCommand(TestCommand command)
|
||||
{
|
||||
if (command == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (command is IEnumerableTestMethodCommand)
|
||||
{
|
||||
return (IEnumerableTestMethodCommand)command;
|
||||
}
|
||||
|
||||
if (command is DelegatingTestCommand)
|
||||
{
|
||||
var delegatingTestCommand = (DelegatingTestCommand)command;
|
||||
return FindFirstIEnumerableTestMethodCommand(delegatingTestCommand.GetInnerCommand());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected override IEnumerable PerformWork()
|
||||
{
|
||||
if (IsCancelledRun())
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
if (m_DontRunRestoringResult)
|
||||
{
|
||||
if (EditModeTestCallbacks.RestoringTestContext == null)
|
||||
{
|
||||
throw new NullReferenceException("RestoringTestContext is not set");
|
||||
}
|
||||
EditModeTestCallbacks.RestoringTestContext();
|
||||
Result = Context.CurrentResult;
|
||||
yield break;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (IsCancelledRun())
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
if (m_Command is SkipCommand)
|
||||
{
|
||||
m_Command.Execute(Context);
|
||||
Result = Context.CurrentResult;
|
||||
yield break;
|
||||
}
|
||||
|
||||
//Check if we can execute this test
|
||||
var firstEnumerableCommand = FindFirstIEnumerableTestMethodCommand(m_Command);
|
||||
if (firstEnumerableCommand == null)
|
||||
{
|
||||
Context.CurrentResult.SetResult(ResultState.Error, "Returning IEnumerator but not using test attribute supporting this");
|
||||
yield break;
|
||||
}
|
||||
|
||||
if (m_Command.Test.Method.ReturnType.IsType(typeof(IEnumerator)))
|
||||
{
|
||||
if (m_Command is ApplyChangesToContextCommand)
|
||||
{
|
||||
var applyChangesToContextCommand = ((ApplyChangesToContextCommand)m_Command);
|
||||
applyChangesToContextCommand.ApplyChanges(Context);
|
||||
m_Command = applyChangesToContextCommand.GetInnerCommand();
|
||||
}
|
||||
|
||||
var innerCommand = (IEnumerableTestMethodCommand)m_Command;
|
||||
if (innerCommand == null)
|
||||
{
|
||||
Debug.Log("failed getting innerCommand");
|
||||
throw new Exception("Tests returning IEnumerator can only use test attributes handling those");
|
||||
}
|
||||
|
||||
foreach (var workItemStep in innerCommand.ExecuteEnumerable(Context))
|
||||
{
|
||||
if (IsCancelledRun())
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
if (workItemStep is TestEnumerator)
|
||||
{
|
||||
if (EnumeratorStepHelper.UpdateEnumeratorPcIfNeeded(TestEnumerator.Enumerator))
|
||||
{
|
||||
yield return new RestoreTestContextAfterDomainReload();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (workItemStep is AsyncOperation)
|
||||
{
|
||||
var asyncOperation = (AsyncOperation)workItemStep;
|
||||
while (!asyncOperation.isDone)
|
||||
{
|
||||
if (IsCancelledRun())
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
yield return null;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
ResultedInDomainReload = false;
|
||||
|
||||
if (workItemStep is IEditModeTestYieldInstruction)
|
||||
{
|
||||
var editModeTestYieldInstruction = (IEditModeTestYieldInstruction)workItemStep;
|
||||
yield return editModeTestYieldInstruction;
|
||||
var enumerator = editModeTestYieldInstruction.Perform();
|
||||
while (true)
|
||||
{
|
||||
bool moveNext;
|
||||
try
|
||||
{
|
||||
moveNext = enumerator.MoveNext();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Context.CurrentResult.RecordException(e);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!moveNext)
|
||||
{
|
||||
break;
|
||||
}
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
yield return workItemStep;
|
||||
}
|
||||
}
|
||||
|
||||
Result = Context.CurrentResult;
|
||||
EditorApplication.isPlaying = false;
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
WorkItemComplete();
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsCancelledRun()
|
||||
{
|
||||
return Context.ExecutionStatus == TestExecutionStatus.AbortRequested || Context.ExecutionStatus == TestExecutionStatus.StopRequested;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1ebc1994f9a3d5649a1201d3a84b38df
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,51 @@
|
||||
using System.Collections;
|
||||
using System.Reflection;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner
|
||||
{
|
||||
internal class EnumeratorStepHelper
|
||||
{
|
||||
private static int m_PC;
|
||||
|
||||
public static void SetEnumeratorPC(int pc)
|
||||
{
|
||||
m_PC = pc;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current enumerator PC
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// The PC
|
||||
/// 0 if no current Enumeration
|
||||
/// </returns>
|
||||
public static int GetEnumeratorPC(IEnumerator enumerator)
|
||||
{
|
||||
if (enumerator == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return (int)GetPCFieldInfo(enumerator).GetValue(enumerator);
|
||||
}
|
||||
|
||||
public static bool UpdateEnumeratorPcIfNeeded(IEnumerator enumerator)
|
||||
{
|
||||
if (m_PC > 0)
|
||||
{
|
||||
GetPCFieldInfo(enumerator).SetValue(enumerator, m_PC);
|
||||
m_PC = 0;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static FieldInfo GetPCFieldInfo(IEnumerator enumerator)
|
||||
{
|
||||
var field = enumerator.GetType().GetField("$PC", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
if (field == null) // Roslyn
|
||||
field = enumerator.GetType().GetField("<>1__state", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
|
||||
return field;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 901b761c5c1e22d4e8a3ba7d95bc1f5d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d9682e749d3efc642af54d789d9090a6
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using UnityEditor;
|
||||
|
||||
namespace UnityEngine.TestTools
|
||||
{
|
||||
public class EnterPlayMode : IEditModeTestYieldInstruction
|
||||
{
|
||||
public bool ExpectDomainReload { get; }
|
||||
public bool ExpectedPlaymodeState { get; private set; }
|
||||
|
||||
public EnterPlayMode(bool expectDomainReload = true)
|
||||
{
|
||||
ExpectDomainReload = expectDomainReload;
|
||||
}
|
||||
|
||||
public IEnumerator Perform()
|
||||
{
|
||||
if (EditorApplication.isPlaying)
|
||||
{
|
||||
throw new Exception("Editor is already in PlayMode");
|
||||
}
|
||||
if (EditorUtility.scriptCompilationFailed)
|
||||
{
|
||||
throw new Exception("Script compilation failed");
|
||||
}
|
||||
yield return null;
|
||||
ExpectedPlaymodeState = true;
|
||||
|
||||
EditorApplication.UnlockReloadAssemblies();
|
||||
EditorApplication.isPlaying = true;
|
||||
|
||||
while (!EditorApplication.isPlaying)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9bd5a110ed89025499ddee8c7e73778e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using UnityEditor;
|
||||
|
||||
namespace UnityEngine.TestTools
|
||||
{
|
||||
public class ExitPlayMode : IEditModeTestYieldInstruction
|
||||
{
|
||||
public bool ExpectDomainReload { get; }
|
||||
public bool ExpectedPlaymodeState { get; private set; }
|
||||
|
||||
public ExitPlayMode()
|
||||
{
|
||||
ExpectDomainReload = false;
|
||||
ExpectedPlaymodeState = false;
|
||||
}
|
||||
|
||||
public IEnumerator Perform()
|
||||
{
|
||||
if (!EditorApplication.isPlayingOrWillChangePlaymode)
|
||||
{
|
||||
throw new Exception("Editor is already in EditMode");
|
||||
}
|
||||
|
||||
EditorApplication.isPlaying = false;
|
||||
while (EditorApplication.isPlaying)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 408674d91d506a54aac9a7f07951c018
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using UnityEditor;
|
||||
|
||||
namespace UnityEngine.TestTools
|
||||
{
|
||||
internal class RecompileScripts : IEditModeTestYieldInstruction
|
||||
{
|
||||
public RecompileScripts() : this(true)
|
||||
{
|
||||
}
|
||||
|
||||
public RecompileScripts(bool expectScriptCompilation) : this(expectScriptCompilation, true)
|
||||
{
|
||||
}
|
||||
|
||||
public RecompileScripts(bool expectScriptCompilation, bool expectScriptCompilationSuccess)
|
||||
{
|
||||
ExpectScriptCompilation = expectScriptCompilation;
|
||||
ExpectScriptCompilationSuccess = expectScriptCompilationSuccess;
|
||||
ExpectDomainReload = true;
|
||||
}
|
||||
|
||||
public bool ExpectDomainReload { get; private set; }
|
||||
public bool ExpectedPlaymodeState { get; }
|
||||
public bool ExpectScriptCompilation { get; private set; }
|
||||
public bool ExpectScriptCompilationSuccess { get; private set; }
|
||||
public static RecompileScripts Current { get; private set; }
|
||||
|
||||
public IEnumerator Perform()
|
||||
{
|
||||
Current = this;
|
||||
|
||||
// We need to yield, to give the test runner a chance to prepare for the domain reload
|
||||
// If the script compilation happens very fast, then EditModeRunner.MoveNextAndUpdateYieldObject will not have a chance to set m_CurrentYieldObject
|
||||
// This really should be fixed in EditModeRunner.MoveNextAndUpdateYieldObject
|
||||
yield return null;
|
||||
|
||||
AssetDatabase.Refresh();
|
||||
|
||||
if (ExpectScriptCompilation && !EditorApplication.isCompiling)
|
||||
{
|
||||
Current = null;
|
||||
throw new Exception("Editor does not need to recompile scripts");
|
||||
}
|
||||
|
||||
EditorApplication.UnlockReloadAssemblies();
|
||||
|
||||
while (EditorApplication.isCompiling)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
|
||||
Current = null;
|
||||
|
||||
if (ExpectScriptCompilationSuccess && EditorUtility.scriptCompilationFailed)
|
||||
{
|
||||
EditorApplication.LockReloadAssemblies();
|
||||
throw new Exception("Script compilation failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9202fbba95ea8294cb5e718f028f21b0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using UnityEditor;
|
||||
|
||||
namespace UnityEngine.TestTools
|
||||
{
|
||||
internal class WaitForDomainReload : IEditModeTestYieldInstruction
|
||||
{
|
||||
public WaitForDomainReload()
|
||||
{
|
||||
ExpectDomainReload = true;
|
||||
}
|
||||
|
||||
public bool ExpectDomainReload { get; }
|
||||
public bool ExpectedPlaymodeState { get; }
|
||||
|
||||
public IEnumerator Perform()
|
||||
{
|
||||
EditorApplication.UnlockReloadAssemblies();
|
||||
|
||||
// Detect if AssetDatabase.Refresh was called (true) or if it will be called on next tick
|
||||
bool isAsync = EditorApplication.isCompiling;
|
||||
|
||||
yield return null;
|
||||
|
||||
if (!isAsync)
|
||||
{
|
||||
EditorApplication.LockReloadAssemblies();
|
||||
throw new Exception("Expected domain reload, but it did not occur");
|
||||
}
|
||||
|
||||
while (EditorApplication.isCompiling)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
|
||||
if (EditorUtility.scriptCompilationFailed)
|
||||
{
|
||||
EditorApplication.LockReloadAssemblies();
|
||||
throw new Exception("Script compilation failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5df3c21c5237c994db89660fbdfee07d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,98 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner
|
||||
{
|
||||
[Serializable]
|
||||
internal class TestFileCleanupVerifier
|
||||
{
|
||||
const string k_Indent = " ";
|
||||
|
||||
[SerializeField]
|
||||
List<string> m_ExistingFiles;
|
||||
|
||||
[SerializeField]
|
||||
bool m_ExistingFilesScanned;
|
||||
|
||||
public Action<object> logAction = Debug.LogWarning;
|
||||
|
||||
private Func<string[]> getAllAssetPathsAction;
|
||||
public Func<string[]> GetAllAssetPathsAction
|
||||
{
|
||||
get
|
||||
{
|
||||
if (getAllAssetPathsAction != null)
|
||||
{
|
||||
return getAllAssetPathsAction;
|
||||
}
|
||||
return AssetDatabase.GetAllAssetPaths;
|
||||
}
|
||||
set
|
||||
{
|
||||
getAllAssetPathsAction = value;
|
||||
}
|
||||
}
|
||||
|
||||
public void RegisterExistingFiles()
|
||||
{
|
||||
if (m_ExistingFilesScanned)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_ExistingFiles = GetAllFilesInAssetsDirectory().ToList();
|
||||
m_ExistingFilesScanned = true;
|
||||
}
|
||||
|
||||
public void VerifyNoNewFilesAdded()
|
||||
{
|
||||
var currentFiles = GetAllFilesInAssetsDirectory().ToList();
|
||||
|
||||
//Expect that if its the same amount of files, there havent been any changes
|
||||
//This is to optimize if there are many files
|
||||
if (currentFiles.Count != m_ExistingFiles.Count)
|
||||
{
|
||||
LogWarningForFilesIfAny(currentFiles.Except(m_ExistingFiles));
|
||||
}
|
||||
}
|
||||
|
||||
void LogWarningForFilesIfAny(IEnumerable<string> filePaths)
|
||||
{
|
||||
if (!filePaths.Any())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var stringWriter = new StringWriter();
|
||||
stringWriter.WriteLine("Files generated by test without cleanup.");
|
||||
stringWriter.WriteLine(k_Indent + "Found {0} new files.", filePaths.Count());
|
||||
|
||||
foreach (var filePath in filePaths)
|
||||
{
|
||||
stringWriter.WriteLine(k_Indent + filePath);
|
||||
}
|
||||
|
||||
LogAction(stringWriter.ToString());
|
||||
}
|
||||
|
||||
private void LogAction(object obj)
|
||||
{
|
||||
if (this.logAction != null)
|
||||
{
|
||||
this.logAction(obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning(obj);
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<string> GetAllFilesInAssetsDirectory()
|
||||
{
|
||||
return GetAllAssetPathsAction();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d6e23541e3b2fea489be46f704b64707
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1f5bbb88ca730434483440cbc0278ef6
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor.TestTools.TestRunner.Api;
|
||||
using UnityEngine.TestRunner.NUnitExtensions;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner
|
||||
{
|
||||
internal class CachingTestListProvider
|
||||
{
|
||||
private readonly ITestListProvider m_InnerTestListProvider;
|
||||
private readonly ITestListCache m_TestListCache;
|
||||
private readonly ITestAdaptorFactory m_TestAdaptorFactory;
|
||||
public CachingTestListProvider(ITestListProvider innerTestListProvider, ITestListCache testListCache, ITestAdaptorFactory testAdaptorFactory)
|
||||
{
|
||||
m_InnerTestListProvider = innerTestListProvider;
|
||||
m_TestListCache = testListCache;
|
||||
m_TestAdaptorFactory = testAdaptorFactory;
|
||||
}
|
||||
|
||||
public IEnumerator<ITestAdaptor> GetTestListAsync(TestPlatform platform)
|
||||
{
|
||||
var testFromCache = m_TestListCache.GetTestFromCacheAsync(platform);
|
||||
while (testFromCache.MoveNext())
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
|
||||
|
||||
if (testFromCache.Current != null)
|
||||
{
|
||||
yield return testFromCache.Current;
|
||||
}
|
||||
else
|
||||
{
|
||||
var test = m_InnerTestListProvider.GetTestListAsync(platform);
|
||||
while (test.MoveNext())
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
|
||||
test.Current.ParseForNameDuplicates();
|
||||
m_TestListCache.CacheTest(platform, test.Current);
|
||||
yield return m_TestAdaptorFactory.Create(test.Current);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 26f3e7301af463c4ca72fa98d59b429e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,13 @@
|
||||
using System.Linq;
|
||||
using UnityEngine.TestTools.Utils;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner
|
||||
{
|
||||
internal class EditorAssembliesProxy : IEditorAssembliesProxy
|
||||
{
|
||||
public IAssemblyWrapper[] loadedAssemblies
|
||||
{
|
||||
get { return EditorAssemblies.loadedAssemblies.Select(x => new EditorAssemblyWrapper(x)).ToArray(); }
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f96d0ea807c081145a1170ed1b6d71e0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,18 @@
|
||||
using System.Reflection;
|
||||
using UnityEngine.TestTools.Utils;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner
|
||||
{
|
||||
internal class EditorAssemblyWrapper : AssemblyWrapper
|
||||
{
|
||||
public EditorAssemblyWrapper(Assembly assembly)
|
||||
: base(assembly) {}
|
||||
|
||||
public override AssemblyName[] GetReferencedAssemblies()
|
||||
{
|
||||
return Assembly.GetReferencedAssemblies();
|
||||
}
|
||||
|
||||
public override string Location { get { return Assembly.Location; } }
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 20cdb37e6fea6d946bbb84d2c923db85
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,17 @@
|
||||
using UnityEditor.Scripting.ScriptCompilation;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner
|
||||
{
|
||||
internal class EditorCompilationInterfaceProxy : IEditorCompilationInterfaceProxy
|
||||
{
|
||||
public ScriptAssembly[] GetAllEditorScriptAssemblies()
|
||||
{
|
||||
return EditorCompilationInterface.Instance.GetAllEditorScriptAssemblies(EditorCompilationInterface.GetAdditionalEditorScriptCompilationOptions());
|
||||
}
|
||||
|
||||
public PrecompiledAssembly[] GetAllPrecompiledAssemblies()
|
||||
{
|
||||
return EditorCompilationInterface.Instance.GetAllPrecompiledAssemblies();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c9b23632c77de204abfe8bf7168d48c0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,69 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using UnityEditor.Scripting.ScriptCompilation;
|
||||
using UnityEngine.TestTools;
|
||||
using UnityEngine.TestTools.Utils;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner
|
||||
{
|
||||
internal class EditorLoadedTestAssemblyProvider
|
||||
{
|
||||
private const string k_NunitAssemblyName = "nunit.framework";
|
||||
private const string k_TestRunnerAssemblyName = "UnityEngine.TestRunner";
|
||||
internal const string k_PerformanceTestingAssemblyName = "Unity.PerformanceTesting";
|
||||
|
||||
private readonly IEditorAssembliesProxy m_EditorAssembliesProxy;
|
||||
private readonly ScriptAssembly[] m_AllEditorScriptAssemblies;
|
||||
private readonly PrecompiledAssembly[] m_AllPrecompiledAssemblies;
|
||||
|
||||
public EditorLoadedTestAssemblyProvider(IEditorCompilationInterfaceProxy compilationInterfaceProxy, IEditorAssembliesProxy editorAssembliesProxy)
|
||||
{
|
||||
m_EditorAssembliesProxy = editorAssembliesProxy;
|
||||
m_AllEditorScriptAssemblies = compilationInterfaceProxy.GetAllEditorScriptAssemblies();
|
||||
m_AllPrecompiledAssemblies = compilationInterfaceProxy.GetAllPrecompiledAssemblies();
|
||||
}
|
||||
|
||||
public List<IAssemblyWrapper> GetAssembliesGroupedByType(TestPlatform mode)
|
||||
{
|
||||
var assemblies = GetAssembliesGroupedByTypeAsync(mode);
|
||||
while (assemblies.MoveNext())
|
||||
{
|
||||
}
|
||||
|
||||
return assemblies.Current;
|
||||
}
|
||||
|
||||
public IEnumerator<List<IAssemblyWrapper>> GetAssembliesGroupedByTypeAsync(TestPlatform mode)
|
||||
{
|
||||
IAssemblyWrapper[] loadedAssemblies = m_EditorAssembliesProxy.loadedAssemblies;
|
||||
|
||||
IDictionary<TestPlatform, List<IAssemblyWrapper>> result = new Dictionary<TestPlatform, List<IAssemblyWrapper>>()
|
||||
{
|
||||
{TestPlatform.EditMode, new List<IAssemblyWrapper>() },
|
||||
{TestPlatform.PlayMode, new List<IAssemblyWrapper>() }
|
||||
};
|
||||
|
||||
foreach (var loadedAssembly in loadedAssemblies)
|
||||
{
|
||||
if (loadedAssembly.GetReferencedAssemblies().Any(x => x.Name == k_NunitAssemblyName || x.Name == k_TestRunnerAssemblyName || x.Name == k_PerformanceTestingAssemblyName))
|
||||
{
|
||||
var assemblyName = new FileInfo(loadedAssembly.Location).Name;
|
||||
var scriptAssemblies = m_AllEditorScriptAssemblies.Where(x => x.Filename == assemblyName).ToList();
|
||||
var precompiledAssemblies = m_AllPrecompiledAssemblies.Where(x => new FileInfo(x.Path).Name == assemblyName).ToList();
|
||||
if (scriptAssemblies.Count < 1 && precompiledAssemblies.Count < 1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var assemblyFlags = scriptAssemblies.Any() ? scriptAssemblies.Single().Flags : precompiledAssemblies.Single().Flags;
|
||||
var assemblyType = (assemblyFlags & AssemblyFlags.EditorOnly) == AssemblyFlags.EditorOnly ? TestPlatform.EditMode : TestPlatform.PlayMode;
|
||||
result[assemblyType].Add(loadedAssembly);
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
|
||||
yield return result[mode];
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 033c884ba52437d49bc55935939ef1c6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,9 @@
|
||||
using UnityEngine.TestTools.Utils;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner
|
||||
{
|
||||
internal interface IEditorAssembliesProxy
|
||||
{
|
||||
IAssemblyWrapper[] loadedAssemblies { get; }
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 98808b11e78f6c84a841a6b4bc5a29d2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,10 @@
|
||||
using UnityEditor.Scripting.ScriptCompilation;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner
|
||||
{
|
||||
internal interface IEditorCompilationInterfaceProxy
|
||||
{
|
||||
ScriptAssembly[] GetAllEditorScriptAssemblies();
|
||||
PrecompiledAssembly[] GetAllPrecompiledAssemblies();
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 28c8fcb831e6e734a9f564bc4f495eba
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,13 @@
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework.Interfaces;
|
||||
using UnityEditor.TestTools.TestRunner.Api;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner
|
||||
{
|
||||
interface ITestListCache
|
||||
{
|
||||
void CacheTest(TestPlatform platform, ITest test);
|
||||
IEnumerator<ITestAdaptor> GetTestFromCacheAsync(TestPlatform platform);
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a704c010bcdb1ec4a9f3417b3c393164
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine.TestRunner.TestLaunchers;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner
|
||||
{
|
||||
interface ITestListCacheData
|
||||
{
|
||||
List<TestPlatform> platforms { get; }
|
||||
List<RemoteTestResultDataWithTestData> cachedData { get; }
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7043e9a330ac2d84a80a965ada4589ad
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,11 @@
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework.Interfaces;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner
|
||||
{
|
||||
interface ITestListProvider
|
||||
{
|
||||
IEnumerator<ITest> GetTestListAsync(TestPlatform platform);
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 64689f8b25eadac4da519e96f514b653
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,64 @@
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework.Interfaces;
|
||||
using UnityEditor.TestTools.TestRunner.Api;
|
||||
using UnityEngine.TestRunner.TestLaunchers;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner
|
||||
{
|
||||
internal class TestListCache : ITestListCache
|
||||
{
|
||||
private readonly ITestAdaptorFactory m_TestAdaptorFactory;
|
||||
private readonly IRemoteTestResultDataFactory m_TestResultDataFactory;
|
||||
private readonly ITestListCacheData m_TestListCacheData;
|
||||
|
||||
public TestListCache(ITestAdaptorFactory testAdaptorFactory, IRemoteTestResultDataFactory testResultDataFactory, ITestListCacheData testListCacheData)
|
||||
{
|
||||
m_TestAdaptorFactory = testAdaptorFactory;
|
||||
m_TestResultDataFactory = testResultDataFactory;
|
||||
m_TestListCacheData = testListCacheData;
|
||||
}
|
||||
|
||||
public void CacheTest(TestPlatform platform, ITest test)
|
||||
{
|
||||
var data = m_TestResultDataFactory.CreateFromTest(test);
|
||||
|
||||
var index = m_TestListCacheData.platforms.IndexOf(platform);
|
||||
if (index < 0)
|
||||
{
|
||||
m_TestListCacheData.cachedData.Add(data);
|
||||
m_TestListCacheData.platforms.Add(platform);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_TestListCacheData.cachedData[index] = data;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator<ITestAdaptor> GetTestFromCacheAsync(TestPlatform platform)
|
||||
{
|
||||
var index = m_TestListCacheData.platforms.IndexOf(platform);
|
||||
if (index < 0)
|
||||
{
|
||||
yield return null;
|
||||
yield break;
|
||||
}
|
||||
|
||||
var testData = m_TestListCacheData.cachedData[index];
|
||||
var test = m_TestAdaptorFactory.BuildTreeAsync(testData);
|
||||
while (test.MoveNext())
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
|
||||
yield return test.Current;
|
||||
}
|
||||
|
||||
[Callbacks.DidReloadScripts]
|
||||
private static void ScriptReloaded()
|
||||
{
|
||||
TestListCacheData.instance.cachedData.Clear();
|
||||
TestListCacheData.instance.platforms.Clear();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d685d97a1eb004f49afea0cc982ff728
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,26 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestRunner.TestLaunchers;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner
|
||||
{
|
||||
internal class TestListCacheData : ScriptableSingleton<TestListCacheData>, ITestListCacheData
|
||||
{
|
||||
[SerializeField]
|
||||
private List<TestPlatform> m_Platforms = new List<TestPlatform>();
|
||||
|
||||
[SerializeField]
|
||||
private List<RemoteTestResultDataWithTestData> m_CachedData = new List<RemoteTestResultDataWithTestData>();
|
||||
|
||||
public List<TestPlatform> platforms
|
||||
{
|
||||
get { return m_Platforms; }
|
||||
}
|
||||
|
||||
public List<RemoteTestResultDataWithTestData> cachedData
|
||||
{
|
||||
get { return m_CachedData; }
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f1b6399349763114d9361bc6dfcd025b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor.TestTools.TestRunner.Api;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner
|
||||
{
|
||||
internal class TestListJob
|
||||
{
|
||||
private CachingTestListProvider m_TestListProvider;
|
||||
private TestPlatform m_Platform;
|
||||
private Action<ITestAdaptor> m_Callback;
|
||||
private IEnumerator<ITestAdaptor> m_ResultEnumerator;
|
||||
public TestListJob(CachingTestListProvider testListProvider, TestPlatform platform, Action<ITestAdaptor> callback)
|
||||
{
|
||||
m_TestListProvider = testListProvider;
|
||||
m_Platform = platform;
|
||||
m_Callback = callback;
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
m_ResultEnumerator = m_TestListProvider.GetTestListAsync(m_Platform);
|
||||
EditorApplication.update += EditorUpdate;
|
||||
}
|
||||
|
||||
private void EditorUpdate()
|
||||
{
|
||||
if (!m_ResultEnumerator.MoveNext())
|
||||
{
|
||||
m_Callback(m_ResultEnumerator.Current);
|
||||
EditorApplication.update -= EditorUpdate;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dec9066d4afefe444be0dad3f137730d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NUnit.Framework.Interfaces;
|
||||
using UnityEngine.TestTools;
|
||||
using UnityEngine.TestTools.NUnitExtensions;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner
|
||||
{
|
||||
internal class TestListProvider : ITestListProvider
|
||||
{
|
||||
private readonly EditorLoadedTestAssemblyProvider m_AssemblyProvider;
|
||||
private readonly UnityTestAssemblyBuilder m_AssemblyBuilder;
|
||||
|
||||
public TestListProvider(EditorLoadedTestAssemblyProvider assemblyProvider, UnityTestAssemblyBuilder assemblyBuilder)
|
||||
{
|
||||
m_AssemblyProvider = assemblyProvider;
|
||||
m_AssemblyBuilder = assemblyBuilder;
|
||||
}
|
||||
|
||||
public IEnumerator<ITest> GetTestListAsync(TestPlatform platform)
|
||||
{
|
||||
var assemblies = m_AssemblyProvider.GetAssembliesGroupedByTypeAsync(platform);
|
||||
while (assemblies.MoveNext())
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
|
||||
var settings = UnityTestAssemblyBuilder.GetNUnitTestBuilderSettings(platform);
|
||||
var test = m_AssemblyBuilder.BuildAsync(assemblies.Current.Select(x => x.Assembly).ToArray(), settings);
|
||||
while (test.MoveNext())
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
|
||||
yield return test.Current;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f15cbb987069826429540d0ea0937442
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user