diff --git a/README.md b/README.md
index 4be8a55..2b7fc95 100644
--- a/README.md
+++ b/README.md
@@ -47,33 +47,26 @@ public class MyTestClass
`GameViewResolutionAttribute` is an NUnit test attribute class to set custom resolution to `GameView` before run test.
This attribute can attached to test method, test class (`TestFixture`) and test assembly.
-Can be used with async Test and UnityTest.
+Can be used with sync Test, async Test and UnityTest.
Usage:
```csharp
-using System.Collections;
using NUnit.Framework;
using TestHelper.Attributes;
-using UnityEngine.TestTools;
[TestFixture]
public class MyTestClass
{
- [UnityTest]
+ [Test]
[GameViewResolution(640, 480, "VGA")]
- public IEnumerator MyTestMethod()
+ public void MyTestMethod()
{
- yield return null; // wait for one frame to apply resolution.
-
- // e.g., test using GraphicRaycaster.
+ // e.g., test using GraphicRaycaster, Graphics Tests Framework, etc...
}
}
```
-> **Warning**
-> Wait for one frame to apply resolution.
-
> **Note**
> In batchmode, open `GameView` window.
diff --git a/Runtime/Attributes/GameViewResolutionAttribute.cs b/Runtime/Attributes/GameViewResolutionAttribute.cs
index e840979..0c7f1fa 100644
--- a/Runtime/Attributes/GameViewResolutionAttribute.cs
+++ b/Runtime/Attributes/GameViewResolutionAttribute.cs
@@ -2,10 +2,11 @@
// This software is released under the MIT License.
using System;
+using System.Collections;
using NUnit.Framework;
using NUnit.Framework.Interfaces;
-using NUnit.Framework.Internal;
using UnityEngine;
+using UnityEngine.TestTools;
#if UNITY_EDITOR
using TestHelper.Wrappers.UnityEditor;
using UnityEditor;
@@ -17,7 +18,7 @@ namespace TestHelper.Attributes
/// Set GameView resolution before SetUp test.
///
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method)]
- public class GameViewResolutionAttribute : NUnitAttribute, IApplyToContext
+ public class GameViewResolutionAttribute : NUnitAttribute, IOuterUnityTestAction
{
private readonly uint _width;
private readonly uint _height;
@@ -45,16 +46,6 @@ public GameViewResolutionAttribute(GameViewResolution resolution)
(_width, _height, _name) = resolution.GetParameter();
}
- ///
- public void ApplyToContext(ITestExecutionContext context)
- {
-#if UNITY_2022_2_OR_NEWER
- SetResolutionUsingPlayModeWindow();
-#else
- SetResolution();
-#endif
- }
-
// ReSharper disable once UnusedMember.Local
private void SetResolutionUsingPlayModeWindow()
{
@@ -106,5 +97,22 @@ private void SetResolution()
gameView.SelectedSizeIndex(index);
#endif
}
+
+ ///
+ public IEnumerator BeforeTest(ITest test)
+ {
+#if UNITY_2022_2_OR_NEWER
+ SetResolutionUsingPlayModeWindow();
+#else
+ SetResolution();
+#endif
+ yield return null;
+ }
+
+ ///
+ public IEnumerator AfterTest(ITest test)
+ {
+ yield return null;
+ }
}
}
diff --git a/Tests/Runtime/Attributes/GameViewResolutionAttributeTest.cs b/Tests/Runtime/Attributes/GameViewResolutionAttributeTest.cs
index 02ecaa6..2c5732c 100644
--- a/Tests/Runtime/Attributes/GameViewResolutionAttributeTest.cs
+++ b/Tests/Runtime/Attributes/GameViewResolutionAttributeTest.cs
@@ -13,24 +13,32 @@ namespace TestHelper.Attributes
[UnityPlatform(RuntimePlatform.OSXEditor, RuntimePlatform.WindowsEditor, RuntimePlatform.LinuxEditor)]
public class GameViewResolutionAttributeTest
{
- [Test]
+ [Test, Order(0)]
[GameViewResolution(1920, 1080, "Full HD")]
- public async Task AttachToAsyncTest_SetScreenSizeToFullHD()
+ public void Attach_SetScreenSizeToFullHD()
{
- await Task.Yield(); // Wait to apply change GameView resolution
-
Assert.That(Screen.width, Is.EqualTo(1920));
Assert.That(Screen.height, Is.EqualTo(1080));
}
- [UnityTest]
+ [Test, Order(0)]
+ [GameViewResolution(GameViewResolution.XGA)]
+ public async Task AttachToAsyncTest_SetScreenSizeToFullHD()
+ {
+ Assert.That(Screen.width, Is.EqualTo(1024));
+ Assert.That(Screen.height, Is.EqualTo(768));
+
+ await Task.Yield(); // Not require awaiting before test
+ }
+
+ [UnityTest] // Run last
[GameViewResolution(GameViewResolution.VGA)]
public IEnumerator AttachToUnityTest_SetScreenSizeToVGA()
{
- yield return null; // Wait to apply change GameView resolution
-
Assert.That(Screen.width, Is.EqualTo(640));
Assert.That(Screen.height, Is.EqualTo(480));
+
+ yield return null; // Not require awaiting before test
}
}
}