diff --git a/Runtime/Attributes/FocusGameViewAttribute.cs b/Runtime/Attributes/FocusGameViewAttribute.cs index 359bc49..9d888f2 100644 --- a/Runtime/Attributes/FocusGameViewAttribute.cs +++ b/Runtime/Attributes/FocusGameViewAttribute.cs @@ -23,6 +23,7 @@ public class FocusGameViewAttribute : NUnitAttribute, IApplyToContext { private static Type s_gameView; + /// public void ApplyToContext(ITestExecutionContext context) { #if UNITY_EDITOR diff --git a/Runtime/Attributes/GameViewResolutionAttribute.cs b/Runtime/Attributes/GameViewResolutionAttribute.cs index e25ad54..e840979 100644 --- a/Runtime/Attributes/GameViewResolutionAttribute.cs +++ b/Runtime/Attributes/GameViewResolutionAttribute.cs @@ -45,6 +45,7 @@ public GameViewResolutionAttribute(GameViewResolution resolution) (_width, _height, _name) = resolution.GetParameter(); } + /// public void ApplyToContext(ITestExecutionContext context) { #if UNITY_2022_2_OR_NEWER @@ -54,6 +55,7 @@ public void ApplyToContext(ITestExecutionContext context) #endif } + // ReSharper disable once UnusedMember.Local private void SetResolutionUsingPlayModeWindow() { #if UNITY_EDITOR && UNITY_2022_2_OR_NEWER @@ -62,6 +64,7 @@ private void SetResolutionUsingPlayModeWindow() #endif } + // ReSharper disable once UnusedMember.Local private void SetResolution() { #if UNITY_EDITOR diff --git a/Runtime/Attributes/IgnoreBatchModeAttribute.cs b/Runtime/Attributes/IgnoreBatchModeAttribute.cs index 7749e08..f558873 100644 --- a/Runtime/Attributes/IgnoreBatchModeAttribute.cs +++ b/Runtime/Attributes/IgnoreBatchModeAttribute.cs @@ -36,7 +36,7 @@ void IApplyToTest.ApplyToTest(Test test) } test.RunState = RunState.Ignored; - test.Properties.Set("_SKIPREASON", (object)this._reason); + test.Properties.Set("_SKIPREASON", this._reason); } } } diff --git a/Runtime/Attributes/IgnoreWindowModeAttribute.cs b/Runtime/Attributes/IgnoreWindowModeAttribute.cs index 19c641b..d0adcb0 100644 --- a/Runtime/Attributes/IgnoreWindowModeAttribute.cs +++ b/Runtime/Attributes/IgnoreWindowModeAttribute.cs @@ -36,7 +36,7 @@ void IApplyToTest.ApplyToTest(Test test) } test.RunState = RunState.Ignored; - test.Properties.Set("_SKIPREASON", (object)this._reason); + test.Properties.Set("_SKIPREASON", this._reason); } } } diff --git a/Tests/Runtime/Attributes/FocusGameViewAttributeTest.cs b/Tests/Runtime/Attributes/FocusGameViewAttributeTest.cs index 4516f6d..378c3d3 100644 --- a/Tests/Runtime/Attributes/FocusGameViewAttributeTest.cs +++ b/Tests/Runtime/Attributes/FocusGameViewAttributeTest.cs @@ -1,6 +1,8 @@ // Copyright (c) 2023 Koji Hasegawa. // This software is released under the MIT License. +using System.Collections; +using System.Threading.Tasks; using NUnit.Framework; using UnityEngine; using UnityEngine.TestTools; @@ -11,18 +13,19 @@ namespace TestHelper.Attributes { [TestFixture] + [UnityPlatform(RuntimePlatform.OSXEditor, RuntimePlatform.WindowsEditor, RuntimePlatform.LinuxEditor)] public class FocusGameViewAttributeTest { [Test] [FocusGameView] - [UnityPlatform(RuntimePlatform.OSXEditor, RuntimePlatform.WindowsEditor, RuntimePlatform.LinuxEditor)] - [IgnoreBatchMode("Open GameView in batchmode but can not be focused.")] + [IgnoreBatchMode("Open GameView in batchmode but can not get window.")] public void Attach_GameViewHasFocus() { const string GameView = "UnityEditor.GameView"; const string SimulatorWindow = "UnityEditor.DeviceSimulation.SimulatorWindow"; #if UNITY_EDITOR var focusedWindow = EditorWindow.focusedWindow; + Assert.That(focusedWindow, Is.Not.Null); Assert.That(focusedWindow.GetType().FullName, Is.EqualTo(GameView).Or.EqualTo(SimulatorWindow)); #endif } @@ -34,5 +37,19 @@ public void Attach_KeepBatchmode() { Assert.That(Application.isBatchMode, Is.True); } + + [Test] + [FocusGameView] + public async Task AttachToAsyncTest_Normally() + { + await Task.Yield(); + } + + [UnityTest] + [FocusGameView] + public IEnumerator AttachToUnityTest_Normally() + { + yield return null; + } } } diff --git a/Tests/Runtime/Attributes/GameViewResolutionAttributeTest.cs b/Tests/Runtime/Attributes/GameViewResolutionAttributeTest.cs index cf86dde..02ecaa6 100644 --- a/Tests/Runtime/Attributes/GameViewResolutionAttributeTest.cs +++ b/Tests/Runtime/Attributes/GameViewResolutionAttributeTest.cs @@ -1,6 +1,7 @@ // Copyright (c) 2023 Koji Hasegawa. // This software is released under the MIT License. +using System.Collections; using System.Threading.Tasks; using NUnit.Framework; using UnityEngine; @@ -14,7 +15,7 @@ public class GameViewResolutionAttributeTest { [Test] [GameViewResolution(1920, 1080, "Full HD")] - public async Task Attach_SetScreenSizeToFullHD() + public async Task AttachToAsyncTest_SetScreenSizeToFullHD() { await Task.Yield(); // Wait to apply change GameView resolution @@ -22,11 +23,11 @@ public async Task Attach_SetScreenSizeToFullHD() Assert.That(Screen.height, Is.EqualTo(1080)); } - [Test] + [UnityTest] [GameViewResolution(GameViewResolution.VGA)] - public async Task Attach_SetScreenSizeToVGA() + public IEnumerator AttachToUnityTest_SetScreenSizeToVGA() { - await Task.Yield(); // Wait to apply change GameView resolution + yield return null; // Wait to apply change GameView resolution Assert.That(Screen.width, Is.EqualTo(640)); Assert.That(Screen.height, Is.EqualTo(480)); diff --git a/Tests/Runtime/Attributes/IgnoreBatchModeAttributeTest.cs b/Tests/Runtime/Attributes/IgnoreBatchModeAttributeTest.cs index aed61e6..0a042c9 100644 --- a/Tests/Runtime/Attributes/IgnoreBatchModeAttributeTest.cs +++ b/Tests/Runtime/Attributes/IgnoreBatchModeAttributeTest.cs @@ -1,8 +1,11 @@ // Copyright (c) 2023 Koji Hasegawa. // This software is released under the MIT License. +using System.Collections; +using System.Threading.Tasks; using NUnit.Framework; using UnityEngine; +using UnityEngine.TestTools; namespace TestHelper.Attributes { @@ -11,9 +14,25 @@ public class IgnoreBatchModeAttributeTest { [Test] [IgnoreBatchMode("Test for skip run on batch-mode")] - public void AttachToMethod_SkipOnBatchMode() + public void Attach_SkipOnBatchMode() { Assert.That(Application.isBatchMode, Is.False); } + + [Test] + [IgnoreBatchMode("Test for skip run on batch-mode")] + public async Task AttachToAsyncTest_SkipOnBatchMode() + { + await Task.Yield(); + Assert.That(Application.isBatchMode, Is.False); + } + + [UnityTest] + [IgnoreBatchMode("Test for skip run on batch-mode")] + public IEnumerator AttachToUnityTest_SkipOnBatchMode() + { + yield return null; + Assert.That(Application.isBatchMode, Is.False); + } } } diff --git a/Tests/Runtime/Attributes/IgnoreWindowModeAttributeTest.cs b/Tests/Runtime/Attributes/IgnoreWindowModeAttributeTest.cs index 4fa3ce3..9023ebe 100644 --- a/Tests/Runtime/Attributes/IgnoreWindowModeAttributeTest.cs +++ b/Tests/Runtime/Attributes/IgnoreWindowModeAttributeTest.cs @@ -1,8 +1,11 @@ // Copyright (c) 2023 Koji Hasegawa. // This software is released under the MIT License. +using System.Collections; +using System.Threading.Tasks; using NUnit.Framework; using UnityEngine; +using UnityEngine.TestTools; namespace TestHelper.Attributes { @@ -11,9 +14,25 @@ public class IgnoreWindowModeAttributeTest { [Test] [IgnoreWindowMode("Test for skip run on window-mode")] - public void AttachToMethod_SkipOnWindowMode() + public void Attach_SkipOnWindowMode() { Assert.That(Application.isBatchMode, Is.True); } + + [Test] + [IgnoreWindowMode("Test for skip run on window-mode")] + public async Task AttachToAsyncTest_SkipOnWindowMode() + { + await Task.Yield(); + Assert.That(Application.isBatchMode, Is.True); + } + + [UnityTest] + [IgnoreWindowMode("Test for skip run on window-mode")] + public IEnumerator AttachToUnityTest_SkipOnWindowMode() + { + yield return null; + Assert.That(Application.isBatchMode, Is.True); + } } }