From b6e2f3e5fc1e6c39d72e0566bcb1b766299d561a Mon Sep 17 00:00:00 2001 From: Koji Hasegawa Date: Sat, 28 Oct 2023 21:47:53 +0900 Subject: [PATCH 1/4] Fix README.md --- README.md | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 35e93ec..52bc293 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ public class MyTestClass > **Note** > In batchmode, open `GameView` window. + #### GameViewResolution `GameViewResolutionAttribute` is an NUnit test attribute class to set custom resolution to `GameView` before run test. @@ -77,6 +78,7 @@ public class MyTestClass > **Note** > In batchmode, open `GameView` window. + #### IgnoreBatchMode `IgnoreBatchModeAttribute` is an NUnit test attribute class to skip test execution when run tests with `-batchmode` from the commandline. @@ -109,6 +111,7 @@ public class MyTestClass } ``` + #### IgnoreWindowMode `IgnoreWindowModeAttribute` is an NUnit test attribute class to skip test execution when run tests on Unity editor window. @@ -136,6 +139,7 @@ public class MyTestClass } ``` + #### CreateScene `CreateSceneAttribute` is an NUnit test attribute class to create new scene before running test. @@ -170,6 +174,7 @@ public class MyTestClass > - Create scene run after `OneTimeSetUp` and before `SetUp` > - Create or not `Main Camera` and `Directional Light` can be specified with parameters (default is not create) + #### LoadScene `LoadSceneAttribute` is an NUnit test attribute class to load scene before running test. @@ -206,6 +211,7 @@ public class MyTestClass > - Load scene run after `OneTimeSetUp` and before `SetUp` > - Scene file path is starts with `Assets/` or `Packages/`. And package name using `name` instead of `displayName`, when scenes in the package. (e.g., `Packages/com.nowsprinting.test-helper/Tests/Scenes/Scene.unity`) + #### TakeScreenshot `TakeScreenshotAttribute` is an NUnit test attribute class to take a screenshot and save it to a file after running test. @@ -221,7 +227,6 @@ Usage: ```csharp using NUnit.Framework; using TestHelper.Attributes; -using UnityEngine; [TestFixture] public class MyTestClass @@ -230,7 +235,7 @@ public class MyTestClass [TakeScreenshot] public void MyTestMethod() { - // take screenshot after running the test. + // Take screenshot after running the test. } } ``` @@ -242,6 +247,7 @@ public class MyTestClass > **Note** > If you want to take screenshots at any time, use the [ScreenshotHelper](#ScreenshotHelper) class. + #### TimeScale `TimeScaleAttribute` is an NUnit test attribute class to change the [Time.timeScale](https://docs.unity3d.com/ScriptReference/Time-timeScale.html) during the test running. @@ -337,6 +343,11 @@ You can specify the save directory and/or filename by arguments. Usage: ```csharp +using System.Collections; +using NUnit.Framework; +using TestHelper.Utils; +using UnityEngine.TestTools; + [TestFixture] public class MyTestClass { @@ -355,11 +366,11 @@ public class MyTestClass > - Files with the same name will be overwritten. Please specify filename argument when calling over twice in one method. -## Editor Extensions +### Editor Extensions -### Open Persistent Data Directory +#### Open Persistent Data Directory -Select **Window** > **Open Persistent Data Directory**, which opens the directory pointed to by [persistent data path](https://docs.unity3d.com/ScriptReference/Application-persistentDataPath.html) in the Finder/ File Explorer. +Select **Window** > **Open Persistent Data Directory**, which opens the directory pointed to by [Application.persistentDataPath](https://docs.unity3d.com/ScriptReference/Application-persistentDataPath.html) in the Finder/ File Explorer. From 2a9d2761f287180aaef8bf6065efd66b436df7ed Mon Sep 17 00:00:00 2001 From: Koji Hasegawa Date: Sat, 28 Oct 2023 23:22:57 +0900 Subject: [PATCH 2/4] Add tests --- .../Attributes/TakeScreenshotAttributeTest.cs | 45 ++++++++++++++++++- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/Tests/Runtime/Attributes/TakeScreenshotAttributeTest.cs b/Tests/Runtime/Attributes/TakeScreenshotAttributeTest.cs index 89b7808..f073edd 100644 --- a/Tests/Runtime/Attributes/TakeScreenshotAttributeTest.cs +++ b/Tests/Runtime/Attributes/TakeScreenshotAttributeTest.cs @@ -1,9 +1,12 @@ // Copyright (c) 2023 Koji Hasegawa. // This software is released under the MIT License. +using System.Collections; using System.IO; +using System.Threading.Tasks; using NUnit.Framework; using UnityEngine; +using UnityEngine.TestTools; using UnityEngine.UI; namespace TestHelper.Attributes @@ -32,7 +35,7 @@ public void SetUp() [TakeScreenshot] public void Attach_TakeScreenshotAndSaveToDefaultPath() { - // take screenshot after running the test. + // Take screenshot after running the test. } [Test, Order(1)] @@ -44,13 +47,51 @@ public void Attach_TakeScreenshotAndSaveToDefaultPath_AfterRunningTest_ExistFile Assert.That(path, Does.Exist); } + [Test, Order(0)] + [GameViewResolution(GameViewResolution.VGA)] + [LoadScene("Packages/com.nowsprinting.test-helper/Tests/Scenes/ScreenshotTest.unity")] + [TakeScreenshot] + public async Task AttachToAsyncTest_TakeScreenshotAndSaveToDefaultPath() + { + await Task.Yield(); + // Take screenshot after running the test. + } + + [Test, Order(1)] + public void AttachToAsyncTest_TakeScreenshotAndSaveToDefaultPath_AfterRunningTest_ExistFile() + { + var path = Path.Combine( + _defaultOutputDirectory, + $"{nameof(AttachToAsyncTest_TakeScreenshotAndSaveToDefaultPath)}.png"); + Assert.That(path, Does.Exist); + } + + [UnityTest, Order(0)] + [GameViewResolution(GameViewResolution.VGA)] + [LoadScene("Packages/com.nowsprinting.test-helper/Tests/Scenes/ScreenshotTest.unity")] + [TakeScreenshot] + public IEnumerator AttachToUnityTest_TakeScreenshotAndSaveToDefaultPath() + { + yield return null; + // Take screenshot after running the test. + } + + [Test, Order(1)] + public void AttachToUnityTest_TakeScreenshotAndSaveToDefaultPath_AfterRunningTest_ExistFile() + { + var path = Path.Combine( + _defaultOutputDirectory, + $"{nameof(AttachToUnityTest_TakeScreenshotAndSaveToDefaultPath)}.png"); + Assert.That(path, Does.Exist); + } + [Test, Order(0)] [GameViewResolution(GameViewResolution.VGA)] [LoadScene("Packages/com.nowsprinting.test-helper/Tests/Scenes/ScreenshotTest.unity")] [TakeScreenshot(filename: nameof(AttachWithFilename_TakeScreenshotAndSaveToSpecifyPath) + ".png")] public void AttachWithFilename_TakeScreenshotAndSaveToSpecifyPath() { - // take screenshot after running the test. + // Take screenshot after running the test. } [Test, Order(1)] From 9b5d247f62aa51b801671690324917332f521700 Mon Sep 17 00:00:00 2001 From: Koji Hasegawa Date: Sat, 28 Oct 2023 23:24:43 +0900 Subject: [PATCH 3/4] Add order to GameViewResolutionAttributeTest Set VGA size at last running test. --- Tests/Runtime/Attributes/GameViewResolutionAttributeTest.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/Runtime/Attributes/GameViewResolutionAttributeTest.cs b/Tests/Runtime/Attributes/GameViewResolutionAttributeTest.cs index 02ecaa6..290c39d 100644 --- a/Tests/Runtime/Attributes/GameViewResolutionAttributeTest.cs +++ b/Tests/Runtime/Attributes/GameViewResolutionAttributeTest.cs @@ -13,7 +13,7 @@ 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() { @@ -23,7 +23,7 @@ public async Task AttachToAsyncTest_SetScreenSizeToFullHD() Assert.That(Screen.height, Is.EqualTo(1080)); } - [UnityTest] + [UnityTest, Order(1)] [GameViewResolution(GameViewResolution.VGA)] public IEnumerator AttachToUnityTest_SetScreenSizeToVGA() { From 518b07403bf580ab7dc7f5e48430690a7cd832fb Mon Sep 17 00:00:00 2001 From: Koji Hasegawa Date: Sat, 28 Oct 2023 23:34:15 +0900 Subject: [PATCH 4/4] Fix README.md --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 52bc293..f0cc922 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ public class MyTestClass [FocusGameView] public void MyTestMethod() { - // e.g., test using InputEventTrace of Input System package. + // e.g., Test using InputEventTrace of Input System package. } } ``` @@ -65,9 +65,9 @@ public class MyTestClass [GameViewResolution(640, 480, "VGA")] public IEnumerator MyTestMethod() { - yield return null; // wait for one frame to apply resolution. + yield return null; // Wait for one frame to apply resolution. - // e.g., test using GraphicRaycaster. + // e.g., Test using GraphicRaycaster. } } ``` @@ -103,7 +103,7 @@ public class MyTestClass [IgnoreBatchMode("Using WaitForEndOfFrame.")] public IEnumerator MyTestMethod() { - // e.g., test needs to take a screenshot. + // e.g., Test needs to take a screenshot. yield return new WaitForEndOfFrame(); ImageAssert.AreEqual(expectedTexture, Camera.main, settings);