Skip to content

Commit

Permalink
Merge pull request #32 from nowsprinting/chore/fix_readme
Browse files Browse the repository at this point in the history
Fix README.md and refactor tests
  • Loading branch information
nowsprinting authored Oct 28, 2023
2 parents 914f9a7 + 518b074 commit fdd69cc
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 13 deletions.
29 changes: 20 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ 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.
}
}
```

> **Note**
> In batchmode, open `GameView` window.

#### GameViewResolution

`GameViewResolutionAttribute` is an NUnit test attribute class to set custom resolution to `GameView` before run test.
Expand All @@ -64,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.
}
}
```
Expand All @@ -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.
Expand All @@ -101,14 +103,15 @@ 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);
}
}
```


#### IgnoreWindowMode

`IgnoreWindowModeAttribute` is an NUnit test attribute class to skip test execution when run tests on Unity editor window.
Expand Down Expand Up @@ -136,6 +139,7 @@ public class MyTestClass
}
```


#### CreateScene

`CreateSceneAttribute` is an NUnit test attribute class to create new scene before running test.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -221,7 +227,6 @@ Usage:
```csharp
using NUnit.Framework;
using TestHelper.Attributes;
using UnityEngine;

[TestFixture]
public class MyTestClass
Expand All @@ -230,7 +235,7 @@ public class MyTestClass
[TakeScreenshot]
public void MyTestMethod()
{
// take screenshot after running the test.
// Take screenshot after running the test.
}
}
```
Expand All @@ -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.
Expand Down Expand Up @@ -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
{
Expand All @@ -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.



Expand Down
4 changes: 2 additions & 2 deletions Tests/Runtime/Attributes/GameViewResolutionAttributeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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()
{
Expand Down
45 changes: 43 additions & 2 deletions Tests/Runtime/Attributes/TakeScreenshotAttributeTest.cs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)]
Expand All @@ -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)]
Expand Down

0 comments on commit fdd69cc

Please sign in to comment.