Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
## [1.4.4] - 2024-04-11
- Fix the issue where playmode controller wasn't being set and cleaned up correctly, causing issues post test run. (DSTR-1025)
- Fixed an issue where Oculus Quest headsets might timeout before the test run starts (DSTR-404).
- Fixed a regression where the console output would no longer get attached to the test result for PlayMode.
  • Loading branch information
Unity Technologies committed Apr 11, 2024
1 parent c6e26e6 commit d8e3426
Show file tree
Hide file tree
Showing 34 changed files with 239 additions and 217 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Changelog
## [1.4.4] - 2024-04-11
- Fix the issue where playmode controller wasn't being set and cleaned up correctly, causing issues post test run. (DSTR-1025)
- Fixed an issue where Oculus Quest headsets might timeout before the test run starts (DSTR-404).
- Fixed a regression where the console output would no longer get attached to the test result for PlayMode.

## [1.4.3] - 2024-01-15
- Fixed a performance issue in relation to the new ui, where running a large selection of tests did not perform well. (DSTR-983)
- The test tree no longer is fully expanded when the window is first opened, fixing test tree explosion. (DSTR-985)
Expand Down
2 changes: 1 addition & 1 deletion Documentation~/reference-comparer-vector2.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Use this class to compare two [Vector2](https://docs.unity3d.com/ScriptReference

| Syntax | Description |
| ------------------------------------------ | ------------------------------------------------------------ |
| `Equals(Vector2 expected, Vector2 actual)` | Compares the `actual` and `expected` `Vector2` objects for equality using the [Utils.AreFloatsEqual](./reference-test-utils.md) method. |
| `Equals(Vector2 expected, Vector2 actual)` | Compares the `actual` and `expected` `Vector2` objects for equality using the [Utils.AreFloatsEqual](xref:UnityEngine.TestTools.Utils.Utils.AreFloatsEqual*) method. |

## Example

Expand Down
2 changes: 1 addition & 1 deletion Documentation~/reference-comparer-vector3.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Use this class to compare two [Vector3](https://docs.unity3d.com/ScriptReference

| Syntax | Description |
| ----------------------------------------------- | ------------------------------------------------------------ |
| `bool Equals(Vector3 expected, Vector3 actual)` | Compares the `actual` and `expected` `Vector3` objects for equality using [Utils.AreFloatsEqual](http://todo) to compare the `x`, `y`, and `z` attributes of `Vector3`. |
| `bool Equals(Vector3 expected, Vector3 actual)` | Compares the `actual` and `expected` `Vector3` objects for equality using [Utils.AreFloatsEqual](xref:UnityEngine.TestTools.Utils.Utils.AreFloatsEqual*) to compare the `x`, `y`, and `z` attributes of `Vector3`. |

## Example

Expand Down
2 changes: 1 addition & 1 deletion Documentation~/reference-comparer-vector4.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Use this class to compare two [Vector4](https://docs.unity3d.com/ScriptReference

| Syntax | Description |
| ------------------------------------------------ | ------------------------------------------------------------ |
| `bool Equals(Vector4 expected, Vector4 actual);` | Compares the `actual` and `expected` `Vector4` objects for equality using [Utils.AreFloatsEqual](http://todo) to compare the `x`, `y`, `z`, and `w` attributes of `Vector4`. |
| `bool Equals(Vector4 expected, Vector4 actual);` | Compares the `actual` and `expected` `Vector4` objects for equality using [Utils.AreFloatsEqual](xref:UnityEngine.TestTools.Utils.Utils.AreFloatsEqual*) to compare the `x`, `y`, `z`, and `w` attributes of `Vector4`. |

## Example

Expand Down
2 changes: 1 addition & 1 deletion Documentation~/reference-tests-parameterized.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ public IEnumerator MyTestWithMultipleValues([ValueSource("values")] int value)

## Ignore based on parameters

You can selectively ignore tests based on the parameters supplied to the test method by using the [ParameterizedIgnoreAttribute](xref:UnityEngine.TestTools.ParameterizedIgnoreAttribute).
You can selectively ignore tests based on the parameters supplied to the test method by using the [ParameterizedIgnoreAttribute](xref:UnityEngine.TestTools.ParametrizedIgnoreAttribute).
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private void PerformLegacyCleanup()
private void PerformLegacyPostSuccessfulLaunchAction()
{
var connectionResult = -1;
var maxTryCount = 10;
var maxTryCount = 30;
var tryCount = maxTryCount;
while (tryCount-- > 0 && connectionResult == -1)
{
Expand Down
21 changes: 11 additions & 10 deletions UnityEditor.TestRunner/TestLaunchers/PlayerLauncher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,18 @@ public override void Run()

public void PrepareScene(string sceneName, Scene scene, PlaymodeTestsController runner)
{
CreateBootstrapScene(sceneName, scene, runner, bootstrapRunner =>
runner.AddEventHandlerMonoBehaviour<PlayModeRunnerCallback>();
var commandLineArgs = Environment.GetCommandLineArgs();
if (!commandLineArgs.Contains("-doNotReportTestResultsBackToEditor"))
{
bootstrapRunner.AddEventHandlerMonoBehaviour<PlayModeRunnerCallback>();
var commandLineArgs = Environment.GetCommandLineArgs();
if (!commandLineArgs.Contains("-doNotReportTestResultsBackToEditor"))
{
bootstrapRunner.AddEventHandlerMonoBehaviour<RemoteTestResultSender>();
}
bootstrapRunner.AddEventHandlerMonoBehaviour<PlayerQuitHandler>();
bootstrapRunner.AddEventHandlerScriptableObject<TestRunCallbackListener>();
});
runner.AddEventHandlerMonoBehaviour<RemoteTestResultSender>();
}
runner.AddEventHandlerMonoBehaviour<PlayerQuitHandler>();
runner.AddEventHandlerScriptableObject<TestRunCallbackListener>();

EditorSceneManager.MarkSceneDirty(scene);
AssetDatabase.SaveAssets();
EditorSceneManager.SaveScene(scene, sceneName, false);
}

private static bool BuildAndRunPlayer(PlayerLauncherBuildOptions buildOptions)
Expand Down
133 changes: 1 addition & 132 deletions UnityEditor.TestRunner/TestLaunchers/PlaymodeLauncher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,140 +10,9 @@

namespace UnityEditor.TestTools.TestRunner
{
internal class PlaymodeLauncher : RuntimeTestLauncherBase
internal class PlaymodeLauncher
{
public static bool IsRunning; // This flag is being used by the graphics test framework to detect EditMode/PlayMode.
public static bool HasFinished;
private Scene m_Scene;
private bool m_IsTestSetupPerformed;
private ITestFilter testFilter;
private PlaymodeTestsController m_Runner;

[SerializeField]
private List<Type> m_EventHandlers = new List<Type>();

private string m_SceneName;

public PlaymodeLauncher(PlaymodeTestsControllerSettings settings, string sceneName, Scene scene, PlaymodeTestsController runner) : base(settings)
{
m_SceneName = sceneName;
m_Scene = scene;
m_Runner = runner;
}

public override void Run()
{
HasFinished = false;
IsRunning = true;
m_Settings.consoleErrorPaused = ConsoleWindow.GetConsoleErrorPause();
m_Settings.runInBackgroundValue = Application.runInBackground;
ConsoleWindow.SetConsoleErrorPause(false);
Application.runInBackground = true;

CreateBootstrapScene(m_SceneName, m_Scene, m_Runner, runner =>
{
runner.AddEventHandlerMonoBehaviour<PlayModeRunnerCallback>();
runner.AddEventHandlerScriptableObject<TestRunnerCallback>();

foreach (var eventHandler in m_EventHandlers)
{
var obj = ScriptableObject.CreateInstance(eventHandler);
runner.AddEventHandlerScriptableObject(obj as ITestRunnerListener);
}
});

if (m_Settings.sceneBased)
{
var newListOfScenes =
new List<EditorBuildSettingsScene> {new EditorBuildSettingsScene(m_SceneName, true)};
newListOfScenes.AddRange(EditorBuildSettings.scenes);
EditorBuildSettings.scenes = newListOfScenes.ToArray();
}

EditorApplication.update += UpdateCallback;
}

public void UpdateCallback()
{
try
{
if (m_IsTestSetupPerformed)
{
if (m_Scene.IsValid())
SceneManager.SetActiveScene(m_Scene);
EditorApplication.update -= UpdateCallback;
EditorApplication.isPlaying = true;
}
else
{
testFilter = m_Settings.BuildNUnitFilter();
var runner = LoadTests(testFilter);

var exceptionThrown = ExecutePreBuildSetupMethods(runner.LoadedTest, testFilter);
if (exceptionThrown)
{
EditorApplication.update -= UpdateCallback;
var controller = PlaymodeTestsController.GetController();
ReopenOriginalScene(controller);
CallbacksDelegator.instance.RunFailed("Run Failed: One or more errors in a prebuild setup. See the editor log for details.");
HasFinished = true;
IsRunning = false;
return;
}
m_IsTestSetupPerformed = true;
}
}
catch (Exception ex)
{
EditorApplication.update -= UpdateCallback;
CallbacksDelegator.instance.RunFailed(ex.Message);
HasFinished = true;
IsRunning = false;
throw;
}
}

[InitializeOnLoad]
public class BackgroundWatcher
{
static BackgroundWatcher()
{
EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
}

private static void OnPlayModeStateChanged(PlayModeStateChange state)
{
if (!PlaymodeTestsController.IsControllerOnScene())
return;
var runner = PlaymodeTestsController.GetController();
if (runner == null)
return;
if (state == PlayModeStateChange.ExitingPlayMode)
{
HasFinished = true;
if (runner.m_Runner != null)
{
ExecutePostBuildCleanupMethods(runner.m_Runner.LoadedTest, runner.settings.BuildNUnitFilter(), Application.platform);
}
}
else if (state == PlayModeStateChange.EnteredEditMode)
{
ConsoleWindow.SetConsoleErrorPause(runner.settings.consoleErrorPaused);
Application.runInBackground = runner.settings.runInBackgroundValue;
//reopen the original scene once we exit playmode
ReopenOriginalScene(runner);
}
}
}

protected static void ReopenOriginalScene(PlaymodeTestsController runner)
{
ReopenOriginalScene(runner.settings.originalScene);
}

public void AddEventHandler<T>() where T : ScriptableObject, ITestRunnerListener
{
m_EventHandlers.Add(typeof(T));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@ protected RuntimeTestLauncherBase(PlaymodeTestsControllerSettings mSettings)
{
m_Settings = mSettings;
}
protected void CreateBootstrapScene(string sceneName, Scene scene, PlaymodeTestsController runner, Action<PlaymodeTestsController> runnerSetup)
{
runnerSetup(runner);

EditorSceneManager.MarkSceneDirty(scene);
AssetDatabase.SaveAssets();
EditorSceneManager.SaveScene(scene, sceneName, false);
}

protected UnityTestAssemblyRunner LoadTests(ITestFilter filter)
{
Expand Down
10 changes: 10 additions & 0 deletions UnityEditor.TestRunner/TestRun/Data/TestJobData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ internal class TestJobData : ISerializationCallbackReceiver
[SerializeField]
public EnumerableTestState RetryRepeatState;

[SerializeField]
public SavedProjectSettings OriginalProjectSettings;

public TestJobData(ExecutionSettings settings)
{
guid = Guid.NewGuid().ToString();
Expand All @@ -137,5 +140,12 @@ public void OnAfterDeserialize()
taskInfoStack = new Stack<TaskInfo>(savedTaskInfoStack);
}

[Serializable]
internal class SavedProjectSettings
{
public bool runInBackgroundValue;

public bool consoleErrorPaused;
}
}
}
19 changes: 13 additions & 6 deletions UnityEditor.TestRunner/TestRun/TaskList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public static IEnumerable<TestTaskBase> GetTaskList(ExecutionSettings settings)

// 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();
Expand All @@ -54,29 +58,32 @@ public static IEnumerable<TestTaskBase> GetTaskList(ExecutionSettings settings)
yield return new CreateEventsTask();
yield return new RegisterCallbackDelegatorEventsTask();
yield return new RegisterTestRunCallbackEventsTask();
yield return new PrebuildSetupTask();
yield return new EnableTestOutLoggerTask();

if (editMode)
{
yield return new PrebuildSetupTask();
yield return new InitializeTestProgressTask();
yield return new UpdateTestProgressTask();
yield return new GenerateContextTask();
yield return new EnableTestOutLoggerTask();
yield return new SetupConstructDelegatorTask();
yield return new RunStartedInvocationEvent();
yield return new EditModeRunTask();
yield return new RunFinishedInvocationEvent();
yield return new CleanupConstructDelegatorTask();
yield return new PostbuildCleanupTask();
yield return new CleanUpContext();
}
else
{
yield return new GenerateContextTask();
yield return new LegacyPlayModeRunTask();
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 CleanUpContext();
}
yield return new PostbuildCleanupTask();
yield return new CleanUpContext();
yield return new RestoreSceneSetupTask();
yield return new DeleteBootstrapSceneTask();
yield return new PerformUndoTask();
Expand Down
3 changes: 1 addition & 2 deletions UnityEditor.TestRunner/TestRun/Tasks/BuildActionTaskBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,13 @@ private IEnumerator ExecuteMethods(ITest testTree, ITestFilter testRunnerFilter,
{
exceptions.Add(ex);
}

yield return null;
}

if (exceptions.Count > 0)
{
throw new AggregateException($"One or more exceptions when executing {typeName}.", exceptions);
}
yield break;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ public CleanupTestControllerTask()

public override IEnumerator Execute(TestJobData testJobData)
{
PlaymodeTestsController.ActiveController = null;
if (testJobData.PlaymodeTestsController == null)
{
yield break;
}

testJobData.PlaymodeTestsController.Cleanup();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ public override IEnumerator Execute(TestJobData testJobData)

testJobData.PlayModeSettings = settings;

if (m_saveScene)
{
EditorSceneManager.MarkSceneDirty(testJobData.InitTestScene);
AssetDatabase.SaveAssets();
EditorSceneManager.SaveScene(testJobData.InitTestScene, testJobData.InitTestScenePath, false);
}

yield break;
}
}
Expand Down
1 change: 1 addition & 0 deletions UnityEditor.TestRunner/TestRun/Tasks/EditModeRunTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public override IEnumerator Execute(TestJobData testJobData)
yield break;
}

yield return null; // Allow for setting the test job data after a resume.
var editModeRunner = ScriptableObject.CreateInstance<EditModeRunner>();
testJobData.editModeRunner = editModeRunner;

Expand Down
30 changes: 30 additions & 0 deletions UnityEditor.TestRunner/TestRun/Tasks/EnterPlayModeTask.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d8e3426

Please sign in to comment.