Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for custom attributes attached to async Test and UnityTest #14

Merged
merged 2 commits into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Runtime/Attributes/FocusGameViewAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class FocusGameViewAttribute : NUnitAttribute, IApplyToContext
{
private static Type s_gameView;

/// <inheritdoc />
public void ApplyToContext(ITestExecutionContext context)
{
#if UNITY_EDITOR
Expand Down
3 changes: 3 additions & 0 deletions Runtime/Attributes/GameViewResolutionAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public GameViewResolutionAttribute(GameViewResolution resolution)
(_width, _height, _name) = resolution.GetParameter();
}

/// <inheritdoc />
public void ApplyToContext(ITestExecutionContext context)
{
#if UNITY_2022_2_OR_NEWER
Expand All @@ -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
Expand All @@ -62,6 +64,7 @@ private void SetResolutionUsingPlayModeWindow()
#endif
}

// ReSharper disable once UnusedMember.Local
private void SetResolution()
{
#if UNITY_EDITOR
Expand Down
2 changes: 1 addition & 1 deletion Runtime/Attributes/IgnoreBatchModeAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
2 changes: 1 addition & 1 deletion Runtime/Attributes/IgnoreWindowModeAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
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);
}
}
}