Skip to content

Commit 4bc46b3

Browse files
authored
Merge pull request #9720 from keveleigh/baseplaymodetests
Update more play mode test scripts to inherit BasePlayModeTests for consistent setup / teardown
2 parents eb753dc + 192e4e1 commit 4bc46b3

27 files changed

+99
-323
lines changed

Assets/MRTK/Tests/PlayModeTests/ConstraintTests.cs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,8 @@
2222

2323
namespace Microsoft.MixedReality.Toolkit.Tests
2424
{
25-
public class ConstraintTests
25+
public class ConstraintTests : BasePlayModeTests
2626
{
27-
[UnitySetUp]
28-
public IEnumerator SetUp()
29-
{
30-
PlayModeTestUtilities.Setup();
31-
yield return null;
32-
}
33-
34-
[UnityTearDown]
35-
public IEnumerator TearDown()
36-
{
37-
PlayModeTestUtilities.TearDown();
38-
yield return null;
39-
}
40-
4127
/// <summary>
4228
/// Tests that the MoveAxisConstraint works for various axes.
4329
/// This test uses world space axes.

Assets/MRTK/Tests/PlayModeTests/Core/Providers/Hands/RiggedHandVisualizerTests.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,19 @@
2121

2222
namespace Microsoft.MixedReality.Toolkit.Tests
2323
{
24-
public class RiggedHandVisualizerTests
24+
public class RiggedHandVisualizerTests : BasePlayModeTests
2525
{
2626
private const string RiggedHandProfileName = "TestRiggedHandVisualizationConfigurationProfile";
2727

28-
[UnitySetUp]
29-
public IEnumerator Setup()
28+
public override IEnumerator Setup()
3029
{
31-
3230
var riggedHandProfile = ScriptableObjectExtensions.GetAllInstances<MixedRealityToolkitConfigurationProfile>()
3331
.FirstOrDefault(x => x.name.Equals(RiggedHandProfileName));
3432
PlayModeTestUtilities.Setup(riggedHandProfile);
3533

3634
yield return null;
3735
}
3836

39-
[TearDown]
40-
public void TearDown()
41-
{
42-
PlayModeTestUtilities.TearDown();
43-
}
44-
4537
#if UNITY_2019_3_OR_NEWER
4638
/// <summary>
4739
/// Run a basic pinch test on the rigged hand to make sure nothing crashes and that the mesh updates appropriately

Assets/MRTK/Tests/PlayModeTests/DialogTests.cs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
namespace Microsoft.MixedReality.Toolkit.Tests
2323
{
24-
public class DialogTests
24+
public class DialogTests : BasePlayModeTests
2525
{
2626
// SDK/Features/UX/Prefabs/Slate/Slate.prefab
2727
private const string smallDialogPrefabAssetGuid = "8e686c90124b8e14cbf8093893109e9a";
@@ -33,21 +33,18 @@ public class DialogTests
3333

3434
private const float DialogStabilizationTime = 1.5f;
3535

36-
[UnitySetUp]
37-
public IEnumerator Setup()
36+
public override IEnumerator Setup()
3837
{
39-
PlayModeTestUtilities.Setup();
38+
yield return base.Setup();
4039
TestUtilities.PlayspaceToOriginLookingForward();
4140
yield return null;
4241
}
4342

44-
[UnityTearDown]
45-
public IEnumerator TearDown()
43+
public override IEnumerator TearDown()
4644
{
47-
GameObject.Destroy(dialogGameObject);
48-
GameObject.Destroy(dialogComponent);
49-
PlayModeTestUtilities.TearDown();
50-
yield return null;
45+
Object.Destroy(dialogGameObject);
46+
Object.Destroy(dialogComponent);
47+
yield return base.TearDown();
5148
}
5249

5350
/// <summary>

Assets/MRTK/Tests/PlayModeTests/FocusProviderRaycastTests.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
using Microsoft.MixedReality.Toolkit.Input;
1010
using NUnit.Framework;
1111
using System.Collections;
12-
using System.IO;
1312
using UnityEditor;
1413
using UnityEngine;
1514
using UnityEngine.TestTools;
@@ -19,7 +18,7 @@ namespace Microsoft.MixedReality.Toolkit.Tests
1918
/// <summary>
2019
/// This class is used to test that <see cref="Toolkit.Input.FocusProvider"/> raycasts are selecting the correct focus object.
2120
/// </summary>
22-
public class FocusProviderRaycastTests
21+
public class FocusProviderRaycastTests : BasePlayModeTests
2322
{
2423
private GameObject raycastTestPrefabInstance = null;
2524
private TestPointer pointer = null;
@@ -47,10 +46,9 @@ public IEnumerator TestRaycastProxies()
4746
}
4847
}
4948

50-
[UnitySetUp]
51-
public IEnumerator SetupFocusProviderRaycastTests()
49+
public override IEnumerator Setup()
5250
{
53-
PlayModeTestUtilities.Setup();
51+
yield return base.Setup();
5452

5553
focusProvider = PlayModeTestUtilities.GetInputSystem().FocusProvider;
5654

@@ -62,8 +60,7 @@ public IEnumerator SetupFocusProviderRaycastTests()
6260
yield return null;
6361
}
6462

65-
[UnityTearDown]
66-
public IEnumerator ShutdownFocusProviderRaycastTests()
63+
public override IEnumerator TearDown()
6764
{
6865
if (raycastTestPrefabInstance)
6966
{
@@ -75,8 +72,7 @@ public IEnumerator ShutdownFocusProviderRaycastTests()
7572
focusProvider = null;
7673
pointer = null;
7774

78-
PlayModeTestUtilities.TearDown();
79-
yield return null;
75+
yield return base.TearDown();
8076
}
8177
}
8278
}

Assets/MRTK/Tests/PlayModeTests/FocusProviderTests.cs

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,8 @@
2222

2323
namespace Microsoft.MixedReality.Toolkit.Tests
2424
{
25-
public class FocusProviderTests
25+
public class FocusProviderTests : BasePlayModeTests
2626
{
27-
[UnitySetUp]
28-
public IEnumerator Setup()
29-
{
30-
PlayModeTestUtilities.Setup();
31-
yield return null;
32-
}
33-
34-
[UnityTearDown]
35-
public IEnumerator TearDown()
36-
{
37-
PlayModeTestUtilities.TearDown();
38-
yield return null;
39-
}
40-
4127
/// <summary>
4228
/// Test that the gaze cursor behaves properly with articulated hand pointers.
4329
/// </summary>
@@ -176,14 +162,13 @@ public IEnumerator TestGazeProviderTargetUnityUi()
176162
[UnityTest]
177163
public IEnumerator TestGazeProviderDestroyed()
178164
{
179-
PlayModeTestUtilities.Setup();
180165
yield return PlayModeTestUtilities.WaitForInputSystemUpdate();
181166

182167
// remove the gaze provider and it's components from the scene
183168
GazeProvider gazeProvider = CoreServices.InputSystem.GazeProvider.GameObjectReference.GetComponent<GazeProvider>();
184169
gazeProvider.GazePointer.BaseCursor.Destroy();
185170
DebugUtilities.LogVerbose("Application was playing, destroyed the gaze pointer's BaseCursor");
186-
UnityObjectExtensions.DestroyObject(gazeProvider as Component);
171+
UnityObjectExtensions.DestroyObject(gazeProvider);
187172
gazeProvider = null;
188173

189174
// Ensure that the input system and it's related input sources are able to be reinitialized without issue.
@@ -201,8 +186,6 @@ public IEnumerator TestGazeProviderDestroyed()
201186
[UnityTest]
202187
public IEnumerator TestOverrideFocusDetails()
203188
{
204-
PlayModeTestUtilities.Setup();
205-
206189
var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
207190
yield return null;
208191

@@ -218,10 +201,12 @@ public IEnumerator TestOverrideFocusDetails()
218201
Assert.IsTrue(focusProvider.TryGetFocusDetails(pointer, out focusDetails));
219202
Assert.IsNull(focusDetails.Object);
220203

221-
var newFocusDetails = new Physics.FocusDetails();
222-
newFocusDetails.Object = cube;
223-
newFocusDetails.RayDistance = 10;
224-
newFocusDetails.Point = new Vector3(1, 2, 3);
204+
var newFocusDetails = new Physics.FocusDetails
205+
{
206+
Object = cube,
207+
RayDistance = 10,
208+
Point = new Vector3(1, 2, 3)
209+
};
225210
Assert.IsTrue(focusProvider.TryOverrideFocusDetails(pointer, newFocusDetails));
226211

227212
Assert.IsTrue(focusProvider.TryGetFocusDetails(pointer, out focusDetails));

Assets/MRTK/Tests/PlayModeTests/GltfTests.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,24 @@
2222

2323
namespace Microsoft.MixedReality.Toolkit.Tests
2424
{
25-
public class GltfTests
25+
public class GltfTests : BasePlayModeTests
2626
{
2727
private const string AvocadoCustomAttrGuid = "fea29429b97dbb14b97820f56c74060a";
2828
private const string CubeCustomAttrGuid = "f0bb9fb635c69be4e8526b0fb6b48f39";
2929

3030
private AsyncCoroutineRunner asyncCoroutineRunner;
31-
[UnitySetUp]
32-
public IEnumerator Setup()
31+
32+
public override IEnumerator Setup()
3333
{
34-
PlayModeTestUtilities.Setup();
34+
yield return base.Setup();
3535
asyncCoroutineRunner = new GameObject("AsyncCoroutineRunner").AddComponent<AsyncCoroutineRunner>();
3636
yield return null;
3737
}
3838

39-
[UnityTearDown]
40-
public IEnumerator TearDown()
39+
public override IEnumerator TearDown()
4140
{
42-
PlayModeTestUtilities.TearDown();
43-
GameObject.Destroy(asyncCoroutineRunner.gameObject);
44-
yield return null;
41+
Object.Destroy(asyncCoroutineRunner.gameObject);
42+
yield return base.TearDown();
4543
}
4644

4745
private IEnumerator WaitForTask(Task task)

Assets/MRTK/Tests/PlayModeTests/GridObjectCollectionTests.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,15 @@ namespace Microsoft.MixedReality.Toolkit.Tests
3131
/// You can use GridObjectLayoutControl.cs in the examples package to
3232
/// quickly generate the expected positions used in these tests.
3333
/// </summary>
34-
internal class GridObjectCollectionTests
34+
internal class GridObjectCollectionTests : BasePlayModeTests
3535
{
36-
[UnitySetUp]
37-
public IEnumerator Setup()
36+
public override IEnumerator Setup()
3837
{
39-
PlayModeTestUtilities.Setup();
38+
yield return base.Setup();
4039
TestUtilities.PlayspaceToOriginLookingForward();
4140
yield return null;
4241
}
4342

44-
[UnityTearDown]
45-
public IEnumerator TearDown()
46-
{
47-
PlayModeTestUtilities.TearDown();
48-
yield return null;
49-
}
50-
5143
#region Tests
5244
/// <summary>
5345
/// Tests that grid lays out object correctly for all different anchor types

Assets/MRTK/Tests/PlayModeTests/HandCoachTests.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,18 @@
2121

2222
namespace Microsoft.MixedReality.Toolkit.Tests
2323
{
24-
class HandCoachTests
24+
class HandCoachTests : BasePlayModeTests
2525
{
2626
private const string handCoachRightGuid = "2225b28a6968ba04594a7564e934a679";
2727
private static readonly string handCoachRightPath = AssetDatabase.GUIDToAssetPath(handCoachRightGuid);
2828

29-
[UnitySetUp]
30-
public IEnumerator Setup()
29+
public override IEnumerator Setup()
3130
{
32-
PlayModeTestUtilities.Setup();
31+
yield return base.Setup();
3332
TestUtilities.PlayspaceToOriginLookingForward();
3433
yield return null;
3534
}
3635

37-
[UnityTearDown]
38-
public IEnumerator TearDown()
39-
{
40-
PlayModeTestUtilities.TearDown();
41-
yield return null;
42-
}
43-
4436
#region Tests
4537
/// <summary>
4638
/// Tests that the hand coach is disabled when the hand is brought up

Assets/MRTK/Tests/PlayModeTests/InputEventSystemTests.cs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,8 @@ namespace Microsoft.MixedReality.Toolkit.Tests
2626
using Handle = BaseEventSystem.EventHandlerEntry;
2727
using HandleList = List<BaseEventSystem.EventHandlerEntry>;
2828

29-
class InputEventSystemTests
29+
class InputEventSystemTests : BasePlayModeTests
3030
{
31-
[UnitySetUp]
32-
public IEnumerator Setup()
33-
{
34-
PlayModeTestUtilities.Setup();
35-
yield return null;
36-
}
37-
38-
[UnityTearDown]
39-
public IEnumerator TearDown()
40-
{
41-
PlayModeTestUtilities.TearDown();
42-
yield return null;
43-
}
44-
4531
/// <summary>
4632
/// </summary>
4733
[UnityTest]

Assets/MRTK/Tests/PlayModeTests/InputRayUtilsTests.cs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,21 @@
1414
using Microsoft.MixedReality.Toolkit.Utilities;
1515
using NUnit.Framework;
1616
using System.Collections;
17-
using UnityEditor;
1817
using UnityEngine;
1918
using UnityEngine.TestTools;
2019

2120
namespace Microsoft.MixedReality.Toolkit.Tests
2221
{
2322
// Tests to verify that the ray utilities methods are functioning correctly
24-
public class InputRayUtilsTests
23+
public class InputRayUtilsTests : BasePlayModeTests
2524
{
26-
[UnitySetUp]
27-
public IEnumerator Setup()
25+
public override IEnumerator Setup()
2826
{
29-
PlayModeTestUtilities.Setup();
27+
yield return base.Setup();
3028
TestUtilities.PlayspaceToOriginLookingForward();
3129
yield return null;
3230
}
3331

34-
[UnityTearDown]
35-
public IEnumerator TearDown()
36-
{
37-
PlayModeTestUtilities.TearDown();
38-
yield return null;
39-
}
40-
4132
[UnityTest]
4233
public IEnumerator HeadGazeRayTest()
4334
{

0 commit comments

Comments
 (0)