Skip to content

Commit

Permalink
Add test on attributes attached to async Test and UnityTest
Browse files Browse the repository at this point in the history
  • Loading branch information
nowsprinting committed Oct 21, 2023
1 parent e0f878a commit f1dcfe0
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 8 deletions.
21 changes: 19 additions & 2 deletions Tests/Runtime/Attributes/FocusGameViewAttributeTest.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
}
Expand All @@ -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;
}
}
}
9 changes: 5 additions & 4 deletions Tests/Runtime/Attributes/GameViewResolutionAttributeTest.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -14,19 +15,19 @@ 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

Assert.That(Screen.width, Is.EqualTo(1920));
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));
Expand Down
21 changes: 20 additions & 1 deletion Tests/Runtime/Attributes/IgnoreBatchModeAttributeTest.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -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);
}
}
}
21 changes: 20 additions & 1 deletion Tests/Runtime/Attributes/IgnoreWindowModeAttributeTest.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -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);
}
}
}

0 comments on commit f1dcfe0

Please sign in to comment.