-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d3e274e
commit 9ca1b21
Showing
12 changed files
with
1,068 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (c) 2023 Koji Hasegawa. | ||
// This software is released under the MIT License. | ||
|
||
using System; | ||
using NUnit.Framework; | ||
|
||
namespace TestHelper.Attributes | ||
{ | ||
/// <summary> | ||
/// Temporarily build scene files not added to "Scenes in Build" when running a test. | ||
/// It has the following effects: | ||
/// - Can specify only scene name to `SceneManager.LoadScene()` method | ||
/// - Can load in `SceneManager.LoadScene()` method when running a test on a standalone player. | ||
/// | ||
/// This attribute is effective for the entire test run, not individual tests. | ||
/// So, I recommend specifying it at the assembly level. | ||
/// </summary> | ||
/// <remarks> | ||
/// The name is "Scene*s*" to like a "Scenes in Build". | ||
/// The argument is a single string, but can attach multiple this attribute. | ||
/// </remarks> | ||
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)] | ||
public class ScenesUsingInTestAttribute : NUnitAttribute | ||
{ | ||
internal string ScenePath { get; private set; } | ||
|
||
/// <summary> | ||
/// Specify scene file path to temporarily build when running a test. | ||
/// </summary> | ||
/// <param name="scenePath">Scene path not in "Scenes in Build". | ||
/// The scene file path starts with `Assets/` or `Packages/`, and ends with `.unity`. | ||
/// Use `name` instead of `displayName` in package paths. | ||
/// </param> | ||
public ScenesUsingInTestAttribute(string scenePath) | ||
{ | ||
ScenePath = scenePath; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
Tests/Runtime/Attributes/ScenesUsingInTestAttributeTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright (c) 2023 Koji Hasegawa. | ||
// This software is released under the MIT License. | ||
|
||
using System.Collections; | ||
using System.Diagnostics.CodeAnalysis; | ||
using NUnit.Framework; | ||
using UnityEngine; | ||
using UnityEngine.SceneManagement; | ||
using UnityEngine.TestTools; | ||
|
||
namespace TestHelper.Attributes | ||
{ | ||
[TestFixture] | ||
[SuppressMessage("ReSharper", "Unity.LoadSceneUnexistingScene")] | ||
public class ScenesUsingInTestAttributeTest | ||
{ | ||
[UnityTest] | ||
[ScenesUsingInTest("Packages/com.nowsprinting.test-helper/Tests/Scenes/NotInScenesInBuild.unity")] | ||
public IEnumerator Attach_CanLoadSceneNotIncludedBuild() | ||
{ | ||
yield return SceneManager.LoadSceneAsync("NotInScenesInBuild"); | ||
var cube = GameObject.Find("CubeInNotInScenesInBuild"); | ||
Assert.That(cube, Is.Not.Null); | ||
} | ||
|
||
[UnityTest] | ||
[ScenesUsingInTest("Packages/com.nowsprinting.test-helper/Tests/Scenes/NotInScenesInBuild.unity")] | ||
[ScenesUsingInTest("Packages/com.nowsprinting.test-helper/Tests/Scenes/NotInScenesInBuild2.unity")] | ||
public IEnumerator AttachMultiple_CanLoadScenesNotIncludedBuild() | ||
{ | ||
yield return SceneManager.LoadSceneAsync("NotInScenesInBuild"); | ||
var cube = GameObject.Find("CubeInNotInScenesInBuild"); | ||
Assert.That(cube, Is.Not.Null); | ||
|
||
yield return SceneManager.LoadSceneAsync("NotInScenesInBuild2"); | ||
var cube2 = GameObject.Find("CubeInNotInScenesInBuild2"); | ||
Assert.That(cube2, Is.Not.Null); | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Tests/Runtime/Attributes/ScenesUsingInTestAttributeTest.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.