first commit

This commit is contained in:
lethanhsonvsp
2025-11-17 15:16:36 +07:00
commit a40d0921eb
17012 changed files with 2652386 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 4926c06156894939ba0a2680f1b0aa7a
timeCreated: 1658837036

View File

@@ -0,0 +1,23 @@
using System;
using UnityEngine;
namespace UnityEditor.TestTools.TestRunner.TestRun
{
[Serializable]
internal class RunProgress
{
public const float progressPrTask = 0.0075f;
[SerializeField]
public float progressPrTest;
[SerializeField]
public float progress;
[SerializeField]
public string stageName;
[SerializeField]
public string stepName;
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 19bb2cdbf1454aae9b90c628fb83ad9b
timeCreated: 1659007231

View File

@@ -0,0 +1,21 @@
using System;
using UnityEngine;
namespace UnityEditor.TestTools.TestRunner.TestRun
{
[Serializable]
internal class TaskInfo
{
[SerializeField]
public int index;
[SerializeField]
public int stopBeforeIndex;
[SerializeField]
public int pc;
[SerializeField]
public TaskMode taskMode = TaskMode.Normal;
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0d2e1e2a782748e6acb8565ad040df60
timeCreated: 1658837043

View File

@@ -0,0 +1,13 @@
using System;
namespace UnityEditor.TestTools.TestRunner.TestRun
{
internal enum TaskMode
{
Normal,
Error,
Resume,
EnteredEditMode,
Canceled,
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 06e624de88cb4a808350b63994eb39ed
timeCreated: 1658837058

View File

@@ -0,0 +1,157 @@
using System;
using System.Collections.Generic;
using NUnit.Framework.Interfaces;
using UnityEditor.SceneManagement;
using UnityEditor.TestTools.TestRunner.Api;
using UnityEditor.TestTools.TestRunner.TestRun.Tasks;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.TestRunner.NUnitExtensions.Runner;
using UnityEngine.TestTools;
using UnityEngine.TestTools.NUnitExtensions;
using UnityEngine.TestTools.TestRunner;
namespace UnityEditor.TestTools.TestRunner.TestRun
{
[Serializable]
internal class TestJobData : ISerializationCallbackReceiver
{
[SerializeField]
public string guid;
[SerializeField]
public string startTime;
[NonSerialized]
public Stack<TaskInfo> taskInfoStack = new Stack<TaskInfo>();
[SerializeField]
public int taskPC;
[SerializeField]
public bool isRunning;
[SerializeField]
public ExecutionSettings executionSettings;
[SerializeField]
public RunProgress runProgress = new RunProgress();
[SerializeField]
public string[] existingFiles;
[SerializeField]
public int undoGroup = -1;
[SerializeField]
public EditModeRunner editModeRunner;
[SerializeField]
public BeforeAfterTestCommandState setUpTearDownState;
[SerializeField]
public BeforeAfterTestCommandState outerUnityTestActionState;
[SerializeField]
public TestRunnerStateSerializer testRunnerStateSerializer;
[SerializeField]
public EnumerableTestState enumerableTestState;
[SerializeField]
private TaskInfo[] savedTaskInfoStack;
[NonSerialized]
public bool isHandledByRunner;
[SerializeField]
public SceneSetup[] SceneSetup;
[NonSerialized]
public TestTaskBase[] Tasks;
[SerializeField]
public TestProgress testProgress;
public ITest testTree;
[NonSerialized]
public ITestFilter testFilter;
[NonSerialized]
public TestStartedEvent TestStartedEvent;
[NonSerialized]
public TestFinishedEvent TestFinishedEvent;
[NonSerialized]
public RunStartedEvent RunStartedEvent;
[NonSerialized]
public RunFinishedEvent RunFinishedEvent;
[NonSerialized]
public UnityTestExecutionContext Context;
[NonSerialized]
public ConstructDelegator ConstructDelegator;
[NonSerialized]
public ITestResult TestResults;
[SerializeField]
public Scene InitTestScene;
[SerializeField]
public string InitTestScenePath;
[SerializeField]
public BuildPlayerOptions PlayerBuildOptions;
[SerializeField]
public PlaymodeTestsController PlaymodeTestsController;
[SerializeField]
public PlaymodeTestsControllerSettings PlayModeSettings;
[SerializeField]
public PlatformSpecificSetup PlatformSpecificSetup;
[NonSerialized]
public RuntimePlatform? TargetRuntimePlatform;
[SerializeField]
public EnumerableTestState RetryRepeatState;
[SerializeField]
public SavedProjectSettings OriginalProjectSettings;
[SerializeField]
public int UserApplicationIdleTime = -1;
[SerializeField]
public int UserInteractionMode = -1;
public TestJobData(ExecutionSettings settings)
{
guid = Guid.NewGuid().ToString();
executionSettings = settings;
isRunning = false;
startTime = DateTime.Now.ToString("o");
}
public void OnBeforeSerialize()
{
savedTaskInfoStack = taskInfoStack.ToArray();
}
public void OnAfterDeserialize()
{
taskInfoStack = new Stack<TaskInfo>(savedTaskInfoStack);
}
[Serializable]
internal class SavedProjectSettings
{
public bool runInBackgroundValue;
public bool consoleErrorPaused;
}
}
}

View File

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

View File

@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace UnityEditor.TestTools.TestRunner.TestRun
{
[Serializable]
internal class TestProgress
{
[SerializeField]
public string CurrentTest;
[SerializeField]
public string[] AllTestsToRun;
[SerializeField]
public List<string> RemainingTests;
[SerializeField]
public List<string> CompletedTests;
public TestProgress(string[] allTestsToRun)
{
AllTestsToRun = allTestsToRun;
RemainingTests = allTestsToRun.ToList();
CompletedTests = new List<string>();
}
}
}

View File

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

View File

@@ -0,0 +1,12 @@
using System;
namespace UnityEditor.TestTools.TestRunner.TestRun
{
internal interface ITestJobDataHolder
{
void RegisterRun(ITestJobRunner runner, TestJobData data);
void UnregisterRun(ITestJobRunner runner, TestJobData data);
ITestJobRunner GetRunner(string guid);
ITestJobRunner[] GetAllRunners();
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7d0a7ea6062a4f42bcea6cb642817537
timeCreated: 1658838617

View File

@@ -0,0 +1,12 @@
using System;
namespace UnityEditor.TestTools.TestRunner.TestRun
{
internal interface ITestJobRunner
{
string RunJob(TestJobData data);
bool CancelRun();
bool IsRunningJob();
TestJobData GetData();
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8173ba5b162e4e5882521d173c36acec
timeCreated: 1582105869

View File

@@ -0,0 +1,14 @@
using System;
namespace UnityEditor.TestTools.TestRunner.TestRun
{
internal class RequiredTestRunDataMissingException : Exception
{
public RequiredTestRunDataMissingException(string fieldName) : base($"The test run data '{fieldName}' is required and could not be found.")
{
FieldName = fieldName;
}
public string FieldName;
}
}

View File

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

View File

@@ -0,0 +1,96 @@
using System;
using System.Collections.Generic;
using UnityEditor.SceneManagement;
using UnityEditor.TestTools.TestRunner.Api;
using UnityEditor.TestTools.TestRunner.TestRun.Tasks;
using UnityEditor.TestTools.TestRunner.TestRun.Tasks.Events;
using UnityEditor.TestTools.TestRunner.TestRun.Tasks.Platform;
using UnityEditor.TestTools.TestRunner.TestRun.Tasks.Player;
using UnityEditor.TestTools.TestRunner.TestRun.Tasks.Scene;
using UnityEngine.TestTools;
namespace UnityEditor.TestTools.TestRunner.TestRun
{
// Note: Indentation of the tasklist is purposefully incorrect, to ease comparison with the 2.0 tasklist.
internal static class TaskList
{
public static IEnumerable<TestTaskBase> GetTaskList(ExecutionSettings settings)
{
if (settings == null)
{
yield break;
}
if (settings.PlayerIncluded())
{
yield return new SaveModifiedSceneTask();
yield return new StoreSceneSetupTask();
yield return new CreateBootstrapSceneTask(true, true, NewSceneSetup.EmptyScene);
yield return new DetermineRuntimePlatformTask();
yield return new PlatformSpecificSetupTask();
yield return new LegacyPlayerRunTask();
yield return new PlatformSpecificPostBuildTask();
yield return new PlatformSpecificSuccessfulBuildTask();
yield return new PlatformSpecificSuccessfulLaunchTask();
yield return new WaitForPlayerRunTask();
yield return new PlatformSpecificCleanupTask();
yield return new RestoreSceneSetupTask();
yield return new DeleteBootstrapSceneTask();
yield return new UnlockReloadAssembliesTask();
yield break;
}
// ReSharper disable once BadControlBracesIndent
var editMode = settings.EditModeIncluded() || (PlayerSettings.runPlayModeTestAsEditModeTest && settings.PlayModeInEditorIncluded());
if (!editMode)
{
yield return new MarkRunAsPlayModeTask();
}
yield return new SaveModifiedSceneTask();
yield return new RegisterFilesForCleanupVerificationTask();
yield return new SaveUndoIndexTask();
yield return new StoreSceneSetupTask();
yield return new SetInteractionModeTask();
yield return new RemoveAdditionalUntitledSceneTask();
yield return new ReloadModifiedScenesTask();
yield return new BuildNUnitFilterTask();
yield return new BuildTestTreeTask(editMode ? TestPlatform.EditMode : TestPlatform.PlayMode);
yield return new CreateBootstrapSceneTask(!editMode, !editMode, editMode ? NewSceneSetup.DefaultGameObjects : NewSceneSetup.EmptyScene);
yield return new CreateEventsTask();
yield return new RegisterCallbackDelegatorEventsTask();
yield return new RegisterTestRunCallbackEventsTask();
yield return new PrebuildSetupTask();
yield return new EnableTestOutLoggerTask();
yield return new InitializeTestProgressTask();
yield return new UpdateTestProgressTask();
if (editMode)
{
yield return new GenerateContextTask();
yield return new SetupConstructDelegatorTask();
yield return new RunStartedInvocationEvent();
yield return new EditModeRunTask();
yield return new RunFinishedInvocationEvent();
yield return new CleanupConstructDelegatorTask();
}
else
{
yield return new GenerateContextTask();
yield return new PreparePlayModeRunTask();
yield return new EnterPlayModeTask();
yield return new PlayModeRunTask();
yield return new ExitPlayModeTask();
yield return new RestoreProjectSettingsTask();
yield return new CleanupTestControllerTask();
}
yield return new PostbuildCleanupTask();
yield return new CleanUpContext();
yield return new ResetInteractionModeTask();
yield return new RestoreSceneSetupTask();
yield return new DeleteBootstrapSceneTask();
yield return new PerformUndoTask();
yield return new CleanupVerificationTask();
yield return new UnlockReloadAssembliesTask();
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b1516a46a16d458e8debc6b459b107ea
timeCreated: 1658846478

View File

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

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();
}
}
}

View File

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

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d973b7805df545bdae3986ab72a6c2e8
timeCreated: 1695720017

View File

@@ -0,0 +1,19 @@
using System;
using System.Collections;
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks.Platform
{
internal class PlatformSpecificCleanupTask : TestTaskBase
{
public PlatformSpecificCleanupTask()
{
RunOnError = ErrorRunMode.RunAlways;
}
public override IEnumerator Execute(TestJobData testJobData)
{
testJobData.PlatformSpecificSetup?.CleanUp();
yield break;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0f3326f97c0d472bac74dc480099f983
timeCreated: 1695723368

View File

@@ -0,0 +1,18 @@
using System;
using System.Collections;
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks.Platform
{
internal class PlatformSpecificPostBuildTask : TestTaskBase
{
public override IEnumerator Execute(TestJobData testJobData)
{
if ((testJobData.PlayerBuildOptions.options & BuildOptions.AutoRunPlayer) != 0)
{
testJobData.PlatformSpecificSetup.PostBuildAction();
}
yield return null;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 646cce3bdb8d461d980d11d729ab3312
timeCreated: 1695720480

View File

@@ -0,0 +1,21 @@
using System;
using System.Collections;
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks.Platform
{
internal class PlatformSpecificSetupTask : TestTaskBase
{
public override IEnumerator Execute(TestJobData testJobData)
{
if (testJobData.executionSettings.targetPlatform == null)
{
throw new Exception($"{nameof(PlatformSpecificSetupTask)} can only run on a task with a target platform.");
}
testJobData.PlatformSpecificSetup =
new PlatformSpecificSetup(testJobData.executionSettings.targetPlatform.Value);
testJobData.PlatformSpecificSetup.Setup();
yield break;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 49284fdc918b491aa9f4439e6cc59c9c
timeCreated: 1695720223

View File

@@ -0,0 +1,18 @@
using System;
using System.Collections;
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks.Platform
{
internal class PlatformSpecificSuccessfulBuildTask : TestTaskBase
{
public override IEnumerator Execute(TestJobData testJobData)
{
if ((testJobData.PlayerBuildOptions.options & BuildOptions.AutoRunPlayer) != 0)
{
testJobData.PlatformSpecificSetup.PostSuccessfulBuildAction();
}
yield return null;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 57e7d752d8e6494b9aca2f2724b98761
timeCreated: 1695723269

View File

@@ -0,0 +1,18 @@
using System;
using System.Collections;
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks.Platform
{
internal class PlatformSpecificSuccessfulLaunchTask : TestTaskBase
{
public override IEnumerator Execute(TestJobData testJobData)
{
if ((testJobData.PlayerBuildOptions.options & BuildOptions.AutoRunPlayer) != 0)
{
testJobData.PlatformSpecificSetup.PostSuccessfulLaunchAction();
}
yield return null;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 31d26a10516a4ac7a9bfdcac13a6386e
timeCreated: 1695723321

View File

@@ -0,0 +1,68 @@
using System;
using System.Collections;
using System.Linq;
using UnityEngine;
using UnityEngine.TestRunner.NUnitExtensions.Runner;
using UnityEngine.TestTools.TestRunner;
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks
{
internal class PlayModeRunTask : TestTaskBase
{
public PlayModeRunTask()
{
SupportsResumingEnumerator = true;
}
public override IEnumerator Execute(TestJobData testJobData)
{
yield return null; // Allow for setting the test job data after a resume.
// Saving of the scene causes serialization of the runner, so the events needs to be resubscribed. This is temporary for now.
// Wait for the active controller
while (PlaymodeTestsController.ActiveController == null)
{
yield return null;
}
var controller = PlaymodeTestsController.ActiveController;
if (controller.m_Runner != null && controller.m_Runner.IsTestComplete)
{
//Already finished, likely zero tests.
testJobData.RunStartedEvent.Invoke(controller.m_Runner.LoadedTest);
testJobData.RunFinishedEvent.Invoke(controller.m_Runner.Result);
yield break;
}
controller.runStartedEvent.AddListener(testJobData.RunStartedEvent.Invoke);
controller.testStartedEvent.AddListener(testJobData.TestStartedEvent.Invoke);
controller.testFinishedEvent.AddListener(testJobData.TestFinishedEvent.Invoke);
controller.runFinishedEvent.AddListener(testJobData.RunFinishedEvent.Invoke);
controller.RunInfrastructureHasRegistered = true;
var runDone = false;
controller.runFinishedEvent.AddListener((_) =>
{
runDone = true;
});
while (!runDone)
{
if (controller.RaisedException != null)
{
throw controller.RaisedException;
}
if (!Application.isPlaying)
{
throw new Exception("Playmode tests were aborted because the player was stopped.");
}
yield return null;
}
yield return null;
}
}
}

View File

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

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 94a6220ee1a442249702c9df66e0fe1b
timeCreated: 1695719729

View File

@@ -0,0 +1,19 @@
using System;
using System.Collections;
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks.Player
{
internal class DetermineRuntimePlatformTask : TestTaskBase
{
public override IEnumerator Execute(TestJobData testJobData)
{
var targetPlatform = testJobData.executionSettings.targetPlatform;
if (targetPlatform.HasValue)
{
testJobData.TargetRuntimePlatform = BuildTargetConverter.TryConvertToRuntimePlatform(targetPlatform.Value);
}
yield return null;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 006c3457e983424bbdead50009cd0e00
timeCreated: 1695719739

View File

@@ -0,0 +1,20 @@
using System;
using NUnit.Framework.Interfaces;
using UnityEngine;
using UnityEngine.TestTools;
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks
{
internal class PostbuildCleanupTask : BuildActionTaskBase<IPostBuildCleanup>
{
public PostbuildCleanupTask() : base(new PostbuildCleanupAttributeFinder())
{
RunOnError = ErrorRunMode.RunAlways;
}
protected override void Action(IPostBuildCleanup target)
{
target.Cleanup();
}
}
}

View File

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

View File

@@ -0,0 +1,18 @@
using System;
using UnityEngine;
using UnityEngine.TestTools;
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks
{
internal class PrebuildSetupTask : BuildActionTaskBase<IPrebuildSetup>
{
public PrebuildSetupTask() : base(new PrebuildSetupAttributeFinder())
{
}
protected override void Action(IPrebuildSetup target)
{
target.Setup();
}
}
}

View File

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

View File

@@ -0,0 +1,27 @@
using System;
using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks
{
internal class PreparePlayModeRunTask : TestTaskBase
{
public override IEnumerator Execute(TestJobData testJobData)
{
testJobData.OriginalProjectSettings = new TestJobData.SavedProjectSettings
{
consoleErrorPaused = ConsoleWindow.GetConsoleErrorPause(),
runInBackgroundValue = Application.runInBackground
};
ConsoleWindow.SetConsoleErrorPause(false);
Application.runInBackground = true;
if (testJobData.InitTestScene.IsValid())
{
SceneManager.SetActiveScene(testJobData.InitTestScene);
}
yield break;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b1694e597ba745169b292914291c136b
timeCreated: 1705486325

View File

@@ -0,0 +1,14 @@
using System;
using System.Collections;
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks
{
internal class RegisterFilesForCleanupVerificationTask : FileCleanupVerifierTaskBase
{
public override IEnumerator Execute(TestJobData testJobData)
{
testJobData.existingFiles = GetAllFilesInAssetsDirectory();
yield return null;
}
}
}

View File

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

View File

@@ -0,0 +1,39 @@
using System.Collections;
using System.Reflection;
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks
{
internal class ResetInteractionModeTask : TestTaskBase
{
private const string ApplicationIdleTimeKey = "ApplicationIdleTime";
private const string InteractionModeKey = "InteractionMode";
public ResetInteractionModeTask()
{
RunOnError = ErrorRunMode.RunAlways;
RunOnCancel = true;
}
public override IEnumerator Execute(TestJobData testJobData)
{
#if UNITY_2020_3_OR_NEWER
SetInteractionModeToUserSetting(testJobData);
EditorApplication.UpdateInteractionModeSettings();
#endif
yield break;
}
#if UNITY_2020_3_OR_NEWER
private void SetInteractionModeToUserSetting(TestJobData testJobData)
{
if (testJobData.UserApplicationIdleTime != -1)
{
EditorPrefs.SetInt(ApplicationIdleTimeKey, testJobData.UserApplicationIdleTime);
}
if (testJobData.UserInteractionMode != -1)
{
EditorPrefs.SetInt(InteractionModeKey, testJobData.UserInteractionMode);
}
}
#endif
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5db0e0c612cd489a89d330acbc4ac585
timeCreated: 1713426017

View File

@@ -0,0 +1,25 @@
using System;
using System.Collections;
using UnityEngine;
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks
{
internal class RestoreProjectSettingsTask : TestTaskBase
{
public RestoreProjectSettingsTask()
{
RunOnError = ErrorRunMode.RunAlways;
RunOnCancel = true;
}
public override IEnumerator Execute(TestJobData testJobData)
{
if (testJobData.OriginalProjectSettings == null)
{
yield break;
}
ConsoleWindow.SetConsoleErrorPause(testJobData.OriginalProjectSettings.consoleErrorPaused);
Application.runInBackground = testJobData.OriginalProjectSettings.runInBackgroundValue;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0f691f67e4ca49a386e31761b0ff8238
timeCreated: 1705486535

View File

@@ -0,0 +1,15 @@
using System;
using System.Collections;
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks
{
internal class SaveUndoIndexTask : TestTaskBase
{
internal Func<int> GetUndoGroup = Undo.GetCurrentGroup;
public override IEnumerator Execute(TestJobData testJobData)
{
testJobData.undoGroup = GetUndoGroup();
yield break;
}
}
}

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