From f1dcfe067a21934157d1dd934c8d2af1b1dbeb34 Mon Sep 17 00:00:00 2001 From: Koji Hasegawa Date: Sun, 22 Oct 2023 01:25:58 +0900 Subject: [PATCH] Add test on attributes attached to async Test and UnityTest --- .../Attributes/FocusGameViewAttributeTest.cs | 21 +++++++++++++++++-- .../GameViewResolutionAttributeTest.cs | 9 ++++---- .../IgnoreBatchModeAttributeTest.cs | 21 ++++++++++++++++++- .../IgnoreWindowModeAttributeTest.cs | 21 ++++++++++++++++++- 4 files changed, 64 insertions(+), 8 deletions(-) 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); + } } }