This commit is contained in:
2025-01-17 13:10:42 +01:00
commit 4536213c91
15115 changed files with 1442174 additions and 0 deletions

View File

@@ -0,0 +1,72 @@
using System;
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework.Interfaces;
using UnityEngine;
using UnityEngine.TestTools.Logging;
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks
{
internal abstract class BuildActionTaskBase<T> : TestTaskBase
{
private string typeName;
internal IAttributeFinder attributeFinder;
internal Action<string> logAction = Debug.Log;
internal Func<ILogScope> logScopeProvider = () => new LogScope();
internal Func<Type, object> createInstance = Activator.CreateInstance;
protected BuildActionTaskBase(IAttributeFinder attributeFinder)
{
this.attributeFinder = attributeFinder;
typeName = typeof(T).Name;
}
protected abstract void Action(T target);
public override IEnumerator Execute(TestJobData testJobData)
{
if (testJobData.testTree == null)
{
throw new Exception($"Test tree is not available for {GetType().Name}.");
}
var enumerator = ExecuteMethods(testJobData.testTree, testJobData.testFilter, testJobData.TargetRuntimePlatform ?? Application.platform);
while (enumerator.MoveNext())
{
yield return null;
}
}
private IEnumerator ExecuteMethods(ITest testTree, ITestFilter testRunnerFilter, RuntimePlatform targetPlatform)
{
var exceptions = new List<Exception>();
foreach (var targetClassType in attributeFinder.Search(testTree, testRunnerFilter, targetPlatform))
{
try
{
var targetClass = (T)createInstance(targetClassType);
logAction($"Executing {typeName} for: {targetClassType.FullName}.");
using (var logScope = logScopeProvider())
{
Action(targetClass);
logScope.EvaluateLogScope(true);
}
}
catch (Exception ex)
{
exceptions.Add(ex);
}
}
if (exceptions.Count > 0)
{
throw new AggregateException($"One or more exceptions when executing {typeName}.", exceptions);
}
yield break;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c2441d353f9c42a44af6e224e4901b52
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,25 @@
using System.Collections;
using System.Linq;
using NUnit.Framework.Interfaces;
using NUnit.Framework.Internal.Filters;
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks
{
internal class BuildNUnitFilterTask : TestTaskBase
{
public BuildNUnitFilterTask()
{
RerunAfterResume = true;
}
public override IEnumerator Execute(TestJobData testJobData)
{
var executionSettings = testJobData.executionSettings;
ITestFilter filter = new OrFilter(executionSettings.filters.Select(f => f.ToRuntimeTestRunnerFilter(executionSettings.runSynchronously).BuildNUnitFilter()).ToArray());
testJobData.testFilter = filter;
yield return null;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5640d0c51961421997c9f36f0ec45480
timeCreated: 1594728627

View File

@@ -0,0 +1,61 @@
using System;
using System.Collections;
using System.Linq;
using UnityEditor.TestTools.TestRunner.Api;
using UnityEngine.TestTools;
using UnityEngine.TestTools.NUnitExtensions;
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks
{
internal class BuildTestTreeTask : TestTaskBase
{
private TestPlatform m_TestPlatform;
public BuildTestTreeTask(TestPlatform testPlatform)
{
m_TestPlatform = testPlatform;
RerunAfterResume = true;
}
internal IEditorLoadedTestAssemblyProvider m_testAssemblyProvider = new EditorLoadedTestAssemblyProvider(new EditorCompilationInterfaceProxy(), new EditorAssembliesProxy());
internal Func<string[], int, IAsyncTestAssemblyBuilder> m_testAssemblyBuilderFactory = (orderedTestNames, seed) => new UnityTestAssemblyBuilder(orderedTestNames, seed);
internal ICallbacksDelegator m_CallbacksDelegator = CallbacksDelegator.instance;
public override IEnumerator Execute(TestJobData testJobData)
{
if (testJobData.testTree != null)
{
yield break;
}
var assembliesEnumerator = m_testAssemblyProvider.GetAssembliesGroupedByTypeAsync(m_TestPlatform);
while (assembliesEnumerator.MoveNext())
{
yield return null;
}
if (assembliesEnumerator.Current == null)
{
throw new Exception("Assemblies not retrieved.");
}
var assemblies = assembliesEnumerator.Current.Where(pair => m_TestPlatform.IsFlagIncluded(pair.Key)).SelectMany(pair => pair.Value).Select(x => x.Assembly).ToArray();
var buildSettings = UnityTestAssemblyBuilder.GetNUnitTestBuilderSettings(m_TestPlatform);
var testAssemblyBuilder = m_testAssemblyBuilderFactory(testJobData.executionSettings.orderedTestNames, testJobData.executionSettings.randomOrderSeed);
var enumerator = testAssemblyBuilder.BuildAsync(assemblies, Enumerable.Repeat(m_TestPlatform, assemblies.Length).ToArray(), buildSettings);
while (enumerator.MoveNext())
{
yield return null;
}
var testList = enumerator.Current;
if (testList== null)
{
throw new Exception("Test list not retrieved.");
}
testJobData.testTree = testList;
m_CallbacksDelegator.TestTreeRebuild(testList);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a0288e1c9324e824bab7e2044a72a434
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,16 @@
using System;
using System.Collections;
using NUnit.Framework;
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks
{
internal class CleanUpContext : TestTaskBase
{
public override IEnumerator Execute(TestJobData testJobData)
{
testJobData.Context = null;
TestContext.CurrentTestExecutionContext = null;
yield break;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 1c97cd557b334b27bc325649466d1872
timeCreated: 1669207857

View File

@@ -0,0 +1,14 @@
using System;
using System.Collections;
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks
{
internal class CleanupConstructDelegatorTask : TestTaskBase
{
public override IEnumerator Execute(TestJobData testJobData)
{
testJobData.ConstructDelegator.DestroyCurrentTestObjectIfExists();
yield break;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a155fee568ce42a4b561ee3a27d88532
timeCreated: 1584451388

View File

@@ -0,0 +1,25 @@
using System;
using System.Collections;
using UnityEngine.TestTools.TestRunner;
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks
{
internal class CleanupTestControllerTask : TestTaskBase
{
public CleanupTestControllerTask()
{
RunOnCancel = true;
RunOnError = ErrorRunMode.RunAlways;
}
public override IEnumerator Execute(TestJobData testJobData)
{
if (testJobData.PlaymodeTestsController == null)
{
yield break;
}
testJobData.PlaymodeTestsController.Cleanup();
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 822fa0a65be2467b95721422157c93f0
timeCreated: 1695389918

View File

@@ -0,0 +1,59 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEngine;
using UnityEngine.TestRunner.NUnitExtensions.Runner;
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks
{
internal class CleanupVerificationTask : FileCleanupVerifierTaskBase
{
private const string k_Indent = " ";
internal Action<object> logWarning = Debug.LogWarning;
internal Action<object> logError = Debug.LogError;
public override IEnumerator Execute(TestJobData testJobData)
{
var currentFiles = GetAllFilesInAssetsDirectory();
var existingFiles = testJobData.existingFiles;
if (currentFiles.Length != existingFiles.Length)
{
var existingFilesHashSet = new HashSet<string>(existingFiles);
var newFiles = currentFiles.Where(file => !existingFilesHashSet.Contains(file)).ToArray();
LogWarningForFilesIfAny(newFiles, testJobData.executionSettings.featureFlags.fileCleanUpCheck);
}
yield return null;
}
private void LogWarningForFilesIfAny(string[] filePaths, bool fileCleanUpCheck)
{
if (filePaths.Length == 0)
{
return;
}
var stringWriter = new StringWriter();
stringWriter.WriteLine("Files generated by test without cleanup.");
stringWriter.WriteLine(k_Indent + "Found {0} new files.", filePaths.Length);
foreach (var filePath in filePaths)
{
stringWriter.WriteLine(k_Indent + filePath);
}
if (fileCleanUpCheck)
{
logError(stringWriter.ToString());
}
else
{
logWarning(stringWriter.ToString());
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 93eb6389f4fb6924987867ce0bc339ee
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,74 @@
using System;
using System.Collections;
using System.Linq;
using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.TestTools;
using UnityEngine.TestTools.TestRunner;
using Object = UnityEngine.Object;
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks
{
internal class CreateBootstrapSceneTask : TestTaskBase
{
private bool m_includeTestController;
private bool m_saveScene;
private NewSceneSetup m_SceneSetup;
public CreateBootstrapSceneTask(bool mIncludeTestController, bool saveScene, NewSceneSetup sceneSetup)
{
m_includeTestController = mIncludeTestController;
m_saveScene = saveScene;
m_SceneSetup = sceneSetup;
}
public override IEnumerator Execute(TestJobData testJobData)
{
if (m_saveScene)
{
testJobData.InitTestScenePath = "Assets/InitTestScene" + Guid.NewGuid() + ".unity";
}
testJobData.InitTestScene = EditorSceneManager.NewScene(m_SceneSetup, NewSceneMode.Single);
/* This code from 2.0 is likely not needed and can be removed once backporting has finished.
while (PlaymodeTestsController.IsControllerOnScene())
{
var gameObject = PlaymodeTestsController.GetController().gameObject;
Object.DestroyImmediate(gameObject);
}
*/
var settings = PlaymodeTestsControllerSettings.CreateRunnerSettings(testJobData.executionSettings.filters
.Select(filter => filter.ToRuntimeTestRunnerFilter(testJobData.executionSettings.runSynchronously)).ToArray(), testJobData.executionSettings.orderedTestNames,
testJobData.executionSettings.randomOrderSeed, testJobData.executionSettings.featureFlags, testJobData.executionSettings.retryCount, testJobData.executionSettings.repeatCount, IsAutomated());
if (m_includeTestController)
{
var go = new GameObject(PlaymodeTestsController.kPlaymodeTestControllerName);
var editorLoadedTestAssemblyProvider =
new EditorLoadedTestAssemblyProvider(new EditorCompilationInterfaceProxy(),
new EditorAssembliesProxy());
var runner = go.AddComponent<PlaymodeTestsController>();
runner.AssembliesWithTests = editorLoadedTestAssemblyProvider
.GetAssembliesGroupedByType(TestPlatform.PlayMode).Select(x => x.Assembly.GetName().Name)
.ToList();
runner.settings = settings;
testJobData.PlaymodeTestsController = runner;
}
testJobData.PlayModeSettings = settings;
if (m_saveScene)
{
EditorSceneManager.MarkSceneDirty(testJobData.InitTestScene);
AssetDatabase.SaveAssets();
EditorSceneManager.SaveScene(testJobData.InitTestScene, testJobData.InitTestScenePath, false);
}
yield break;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 4400cdda235b4ea48b9078953ffc8e89
timeCreated: 1695384344

View File

@@ -0,0 +1,24 @@
using System;
using System.Collections;
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks
{
internal class DeleteBootstrapSceneTask : TestTaskBase
{
public DeleteBootstrapSceneTask()
{
RunOnError = ErrorRunMode.RunAlways;
RunOnCancel = true;
}
public override IEnumerator Execute(TestJobData testJobData)
{
if (string.IsNullOrEmpty(testJobData.InitTestScenePath))
{
yield break;
}
AssetDatabase.DeleteAsset(testJobData.InitTestScenePath);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 6465fa5b49fc4c739059189aca21f391
timeCreated: 1695390255

View File

@@ -0,0 +1,55 @@
using System;
using System.Collections;
using UnityEngine;
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks
{
internal class EditModeRunTask : TestTaskBase
{
public EditModeRunTask()
{
SupportsResumingEnumerator = true;
RerunAfterResume = true;
}
public override IEnumerator Execute(TestJobData testJobData)
{
if (testJobData.taskInfoStack.Peek().taskMode == TaskMode.Canceled)
{
var runner = testJobData.editModeRunner;
if (runner != null)
{
runner.OnRunCancel();
}
yield break;
}
else if (testJobData.taskInfoStack.Peek().taskMode == TaskMode.Resume)
{
var runner = testJobData.editModeRunner;
if (runner == null)
{
yield break;
}
runner.Resume(testJobData.executionSettings.BuildNUnitFilter(), testJobData.testTree, testJobData.TestStartedEvent, testJobData.TestFinishedEvent, testJobData.Context);
yield break;
}
yield return null; // Allow for setting the test job data after a resume.
var editModeRunner = ScriptableObject.CreateInstance<EditModeRunner>();
testJobData.editModeRunner = editModeRunner;
editModeRunner.UnityTestAssemblyRunnerFactory = new UnityTestAssemblyRunnerFactory();
editModeRunner.Init(testJobData.executionSettings.BuildNUnitFilter(), testJobData.executionSettings.runSynchronously, testJobData.testTree, testJobData.TestStartedEvent,
testJobData.TestFinishedEvent, testJobData.Context, testJobData.executionSettings.orderedTestNames, testJobData.executionSettings.randomOrderSeed, testJobData.executionSettings.featureFlags.disableNestedEnumeratorBugfix);
while (testJobData.editModeRunner != null && !testJobData.editModeRunner.RunFinished)
{
testJobData.editModeRunner.TestConsumer(testJobData.testRunnerStateSerializer);
yield return null;
}
testJobData.TestResults = testJobData.editModeRunner.m_Runner.Result;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b4246555189b5ee43b4857220f9fd29b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,68 @@
using System;
using System.Collections;
using System.IO;
using NUnit.Framework;
using UnityEditor.TestTools.TestRunner.UnityTestProtocol;
using UnityEngine;
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks
{
internal class EnableTestOutLoggerTask : TestTaskBase, IDisposable
{
internal Action<Action<PlayModeStateChange>> SubscribePlayModeStateChanged = callback =>
EditorApplication.playModeStateChanged += callback;
internal Action<Action<PlayModeStateChange>> UnsubscribePlayModeStateChanged = callback =>
EditorApplication.playModeStateChanged -= callback;
internal Action<Application.LogCallback> SubscribeLogMessageReceivedThreaded =
callback => Application.logMessageReceived += callback;
internal Action<Application.LogCallback> UnsubscribeLogMessageReceivedThreaded =
callback => Application.logMessageReceived -= callback;
internal Func<TextWriter> GetCurrentContextWriter = () => TestContext.Out;
public EnableTestOutLoggerTask()
{
RerunAfterResume = true;
}
public override IEnumerator Execute(TestJobData testJobData)
{
SubscribePlayModeStateChanged(WaitForExitPlaymode);
SubscribeLogMessageReceivedThreaded(LogReceived);
yield break;
}
private void WaitForExitPlaymode(PlayModeStateChange state)
{
if (state == PlayModeStateChange.EnteredEditMode)
{
UnsubscribePlayModeStateChanged(WaitForExitPlaymode);
UnsubscribeLogMessageReceivedThreaded(LogReceived);
SubscribeLogMessageReceivedThreaded(LogReceived);
}
}
private void LogReceived(string message, string stacktrace, LogType type)
{
if (message.StartsWith(UtpDebugLogger.UtpPrefix))
{
return;
}
var writer = GetCurrentContextWriter();
if (writer != null)
{
writer.WriteLine(message);
if (type == LogType.Exception)
{
writer.WriteLine(stacktrace);
}
}
}
public void Dispose()
{
UnsubscribeLogMessageReceivedThreaded(LogReceived);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1a9f3fcee3bd2334593373b00d7b5ca2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,30 @@
using System;
using System.Collections;
using UnityEngine;
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks
{
internal class EnterPlayModeTask : TestTaskBase
{
public Func<bool> IsInPlayMode = () => Application.isPlaying;
public Action EnterPlayMode = () => EditorApplication.isPlaying = true;
public override IEnumerator Execute(TestJobData testJobData)
{
if (IsInPlayMode())
{
yield break;
}
// Give the UI a change to update the progress bar, sa entering playmode freezes.
yield return null;
EnterPlayMode();
while (!IsInPlayMode())
{
yield return null;
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 4b45f42910304b00a63958173ee2c76f
timeCreated: 1588855708

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: cca5935142d6c754f9ecdce1294f7079
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,25 @@
using System;
using System.Collections;
using UnityEngine;
using UnityEngine.TestTools.TestRunner;
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks.Events
{
internal class CreateEventsTask : TestTaskBase
{
public CreateEventsTask()
{
RerunAfterResume = true;
}
public override IEnumerator Execute(TestJobData testJobData)
{
testJobData.RunStartedEvent = new RunStartedEvent();
testJobData.TestStartedEvent = new TestStartedEvent();
testJobData.TestFinishedEvent = new TestFinishedEvent();
testJobData.RunFinishedEvent = new RunFinishedEvent();
yield break;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f2675f346a0926b4aa7928805fd8bc9c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,26 @@
using System;
using System.Collections;
using UnityEditor.TestTools.TestRunner.Api;
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks.Events
{
internal class RegisterCallbackDelegatorEventsTask : TestTaskBase
{
public RegisterCallbackDelegatorEventsTask()
{
RerunAfterResume = true;
}
internal ICallbacksDelegator ApiCallbacksDelegator = CallbacksDelegator.instance;
public override IEnumerator Execute(TestJobData testJobData)
{
ApiCallbacksDelegator.SetTestRunFilter(testJobData.executionSettings.BuildNUnitFilter());
testJobData.RunStartedEvent.AddListener(ApiCallbacksDelegator.RunStarted);
testJobData.TestStartedEvent.AddListener(ApiCallbacksDelegator.TestStarted);
testJobData.TestFinishedEvent.AddListener(ApiCallbacksDelegator.TestFinished);
testJobData.RunFinishedEvent.AddListener(ApiCallbacksDelegator.RunFinished);
yield break;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 311d065aced2092409deadf0c0934f61
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,26 @@
using System;
using System.Collections;
using UnityEngine;
using UnityEngine.TestRunner.Utils;
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks.Events
{
internal class RegisterTestRunCallbackEventsTask : TestTaskBase
{
public RegisterTestRunCallbackEventsTask()
{
RerunAfterResume = true;
}
internal Func<TestRunCallbackListener> GetListener = () => ScriptableObject.CreateInstance<TestRunCallbackListener>();
public override IEnumerator Execute(TestJobData testJobData)
{
var listener = GetListener();
testJobData.RunStartedEvent.AddListener(v => listener.RunStarted(v));
testJobData.TestStartedEvent.AddListener(v => listener.TestStarted(v));
testJobData.TestFinishedEvent.AddListener(v => listener.TestFinished(v));
testJobData.RunFinishedEvent.AddListener(v => listener.RunFinished(v));
yield break;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d9b3520efe42f4ee887f8b99b7e1deae
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,28 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework.Interfaces;
using NUnit.Framework.Internal;
using UnityEditor.TestTools.TestRunner.Api;
using UnityEngine.TestRunner.NUnitExtensions;
using UnityEngine.TestTools.TestRunner;
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks.Events
{
internal class RunFinishedInvocationEvent : TestTaskBase
{
public override IEnumerator Execute(TestJobData testJobData)
{
if (testJobData.TestResults == null)
{
// Temporary workaround to ensure that we do not loose the non serializable results due to a test leaking a domain reload.
testJobData.TestResults = testJobData.editModeRunner.m_Runner.Result;
}
testJobData.editModeRunner.Dispose();
testJobData.RunFinishedEvent.Invoke(testJobData.TestResults);
yield break;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a8ea9765889ae054c9b32cce583af855
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,19 @@
using System;
using System.Collections;
using UnityEngine;
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks.Events
{
internal class RunStartedInvocationEvent : TestTaskBase
{
public override IEnumerator Execute(TestJobData testJobData)
{
if (testJobData.testTree == null)
{
throw new Exception("TestTree must be set before run started event.");
}
testJobData.RunStartedEvent.Invoke(testJobData.testTree);
yield break;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 59267e29055f657429098a57e13debe1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,62 @@
using System;
using System.Collections;
using NUnit.Framework.Interfaces;
using NUnit.Framework.Internal;
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks.Events
{
internal class UpdateTestProgressTask : TestTaskBase
{
private TestProgress m_TestProgress;
public UpdateTestProgressTask()
{
RerunAfterResume = true;
}
public override IEnumerator Execute(TestJobData testJobData)
{
if (testJobData.testProgress == null)
{
throw new RequiredTestRunDataMissingException(nameof(testJobData.testProgress));
}
if (testJobData.TestStartedEvent == null)
{
throw new RequiredTestRunDataMissingException(nameof(testJobData.TestStartedEvent));
}
if (testJobData.TestFinishedEvent == null)
{
throw new RequiredTestRunDataMissingException(nameof(testJobData.TestFinishedEvent));
}
m_TestProgress = testJobData.testProgress;
testJobData.TestStartedEvent.AddListener(TestStarted);
testJobData.TestFinishedEvent.AddListener(TestFinished);
yield break;
}
private void TestStarted(ITest test)
{
if (test.IsSuite || !(test is TestMethod))
{
return;
}
m_TestProgress.CurrentTest = test.Name;
}
private void TestFinished(ITestResult testResult)
{
if (testResult.Test.IsSuite)
{
return;
}
var name = testResult.Test.FullName;
m_TestProgress.RemainingTests.Remove(name);
m_TestProgress.CompletedTests.Add(name);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c5c78f2ef0d32a948bbb93266ef69a6a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,33 @@
using System;
using System.Collections;
using UnityEngine;
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks
{
internal class ExitPlayModeTask : TestTaskBase
{
public ExitPlayModeTask()
{
RunOnCancel = true;
RunOnError = ErrorRunMode.RunAlways;
}
public Func<bool> IsInPlayMode = () => Application.isPlaying;
public Action ExitPlayMode = () => EditorApplication.isPlaying = false;
public override IEnumerator Execute(TestJobData testJobData)
{
if (!IsInPlayMode())
{
yield break;
}
ExitPlayMode();
while (IsInPlayMode())
{
yield return null;
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5842bd968af34a328bb5a3f3c78db54a
timeCreated: 1587459149

View File

@@ -0,0 +1,14 @@
using System;
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks
{
internal abstract class FileCleanupVerifierTaskBase : TestTaskBase
{
internal Func<string[]> GetAllAssetPathsAction = AssetDatabase.GetAllAssetPaths;
protected string[] GetAllFilesInAssetsDirectory()
{
return GetAllAssetPathsAction();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ad7bb166069f8414e9ad26606b305e66
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,50 @@
using System;
using System.Collections;
using System.Linq;
using UnityEditor.TestTools.TestRunner.UnityTestProtocol;
using UnityEngine;
using UnityEngine.TestRunner.NUnitExtensions.Runner;
using UnityEngine.TestTools;
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks
{
internal class GenerateContextTask : TestTaskBase
{
public GenerateContextTask()
{
RerunAfterResume = true;
}
public override IEnumerator Execute(TestJobData testJobData)
{
if (testJobData.taskInfoStack.Peek().taskMode == TaskMode.Normal)
{
testJobData.setUpTearDownState = new BeforeAfterTestCommandState();
testJobData.outerUnityTestActionState = new BeforeAfterTestCommandState();
testJobData.enumerableTestState = new EnumerableTestState();
}
testJobData.Context = new UnityTestExecutionContext()
{
SetUpTearDownState = testJobData.setUpTearDownState,
OuterUnityTestActionState = testJobData.outerUnityTestActionState,
EnumerableTestState = testJobData.enumerableTestState,
Automated = UnityTestProtocolStarter.IsEnabled(),
RetryCount = testJobData.executionSettings.retryCount,
RepeatCount = testJobData.executionSettings.repeatCount,
RetryRepeatState = testJobData.RetryRepeatState
};
if (testJobData.executionSettings.ignoreTests != null)
{
testJobData.Context.IgnoreTests = testJobData.executionSettings.ignoreTests.Select(ignoreTest => ignoreTest.ParseToEngine()).ToArray();
}
testJobData.Context.FeatureFlags = testJobData.executionSettings.featureFlags;
UnityTestExecutionContext.CurrentContext = testJobData.Context;
yield break;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ee6c7dc47e844c3d823b833abbd5f981
timeCreated: 1669207714

View File

@@ -0,0 +1,80 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework.Interfaces;
using UnityEngine;
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks
{
internal class InitializeTestProgressTask : TestTaskBase
{
public InitializeTestProgressTask()
{
RerunAfterResume = true;
}
public override IEnumerator Execute(TestJobData testJobData)
{
testJobData.TestStartedEvent.AddListener(test => OnTestStarted(test, testJobData));
testJobData.TestFinishedEvent.AddListener(test => OnTestFinished(test, testJobData));
if (testJobData.taskInfoStack.Peek().taskMode == TaskMode.Resume)
{
yield break;
}
if (testJobData.testTree == null)
{
throw new RequiredTestRunDataMissingException(nameof(testJobData.testTree));
}
var allTests =
GetTestsExpectedToRun(testJobData.testTree, testJobData.executionSettings.BuildNUnitFilter());
testJobData.testProgress = new TestProgress(allTests.ToArray());
var numTasks = testJobData.Tasks.Count();
var numTests = testJobData.testProgress.AllTestsToRun.Length;
var progressAvailableToTests = 1.0f - numTasks * RunProgress.progressPrTask;
if (numTests > 0)
{
testJobData.runProgress.progressPrTest = progressAvailableToTests / numTests;
}
}
private void OnTestStarted(ITest test, TestJobData data)
{
if (!test.IsSuite)
{
data.runProgress.stepName = test.Name;
}
}
private void OnTestFinished(ITestResult result, TestJobData data)
{
if (!result.Test.IsSuite)
{
data.runProgress.progress += data.runProgress.progressPrTest;
}
}
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;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 83d2df796f82ab847a190a706f00d6eb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,32 @@
using System;
using System.Collections;
using System.Linq;
using UnityEditor.TestRunner.TestLaunchers;
using UnityEngine.TestTools.TestRunner;
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks
{
internal class LegacyPlayerRunTask : TestTaskBase
{
public LegacyPlayerRunTask()
{
SupportsResumingEnumerator = true;
}
public override string GetName()
{
return "Build Test Player";
}
public override IEnumerator Execute(TestJobData testJobData)
{
yield return null; // Allow for setting the test job data after a resume.
var executionSettings = testJobData.executionSettings;
var launcher = new PlayerLauncher(testJobData.PlayModeSettings, executionSettings.targetPlatform, executionSettings.overloadTestRunSettings, executionSettings.playerHeartbeatTimeout, executionSettings.playerSavePath, testJobData.InitTestScenePath, testJobData.InitTestScene, testJobData.PlaymodeTestsController);
launcher.Run();
testJobData.PlayerBuildOptions = launcher.playerBuildOptions.BuildPlayerOptions; // This can be removed once the player build options are created in a separate task
yield return null;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b93fe5bbea454ae438fcec241c5fa85b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,19 @@
using System.Collections;
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks
{
internal class MarkRunAsPlayModeTask : TestTaskBase
{
public MarkRunAsPlayModeTask()
{
RerunAfterResume = true;
}
public override IEnumerator Execute(TestJobData testJobData)
{
// This is a workaround to raise the signal that Playmode Launcher is running.
// It is used by the graphics test framework, as there is no api to provide that information yet.
PlaymodeLauncher.IsRunning = true;
yield break;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 23383565f01f46dfa583710e5108e443
timeCreated: 1705306484

View File

@@ -0,0 +1,39 @@
using System;
using System.Collections;
using UnityEngine;
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks
{
internal class PerformUndoTask : TestTaskBase
{
private const double warningThreshold = 1000;
internal Action<int> RevertAllDownToGroup = Undo.RevertAllDownToGroup;
internal Action<string> LogWarning = Debug.LogWarning;
internal Action<string, string, float> DisplayProgressBar = EditorUtility.DisplayProgressBar;
internal Action ClearProgressBar = EditorUtility.ClearProgressBar;
internal Func<DateTime> TimeNow = () => DateTime.Now;
public override IEnumerator Execute(TestJobData testJobData)
{
if (testJobData.undoGroup < 0)
{
yield break;
}
DisplayProgressBar("Undo", "Reverting changes to the scene", 0);
var undoStartTime = TimeNow();
RevertAllDownToGroup(testJobData.undoGroup);
var timeDelta = TimeNow() - undoStartTime;
if (timeDelta.TotalMilliseconds >= warningThreshold)
{
LogWarning($"Undo after editor test run took {timeDelta.Seconds} second{(timeDelta.Seconds == 1 ? "" : "s")}.");
}
ClearProgressBar();
}
}
}

Some files were not shown because too many files have changed in this diff Show More