Skip to content

Commit

Permalink
Refactor tests in SceneExample using LoadSceneAttribute
Browse files Browse the repository at this point in the history
『Unity Test Framework完全攻略ガイド』10.2.2 および 10.3 で紹介している処理を、
Test Helper パッケージ(com.nowsprinting.test-helper)に含まれる
LoadScene 属性に置き換え。
  • Loading branch information
nowsprinting committed Oct 28, 2023
1 parent e08b14b commit 86f8ab9
Show file tree
Hide file tree
Showing 13 changed files with 15 additions and 160 deletions.
8 changes: 0 additions & 8 deletions Assets/SceneExample/Scripts.meta

This file was deleted.

8 changes: 0 additions & 8 deletions Assets/SceneExample/Scripts/Editor.meta

This file was deleted.

51 changes: 0 additions & 51 deletions Assets/SceneExample/Scripts/Editor/BuildAllScenesForTestPlayer.cs

This file was deleted.

This file was deleted.

16 changes: 0 additions & 16 deletions Assets/SceneExample/Scripts/Editor/SceneExample.Editor.asmdef

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
"name": "SceneExample.Editor.Tests",
"rootNamespace": "SceneExample.Editor",
"references": [
"UnityEngine.TestRunner",
"UnityEditor.TestRunner",
"SceneExample.Editor"
"UnityEditor.TestRunner"
],
"includePlatforms": [
"Editor"
Expand Down
4 changes: 2 additions & 2 deletions Assets/SceneExample/Tests/Runtime/SceneExample.Tests.asmdef
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "SceneExample.Tests",
"rootNamespace": "SceneExample",
"references": [
"UnityEngine.TestRunner",
"UnityEditor.TestRunner"
"UnityEditor.TestRunner",
"TestHelper"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
22 changes: 12 additions & 10 deletions Assets/SceneExample/Tests/Runtime/SceneManagerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using System.Collections;
using NUnit.Framework;
using SceneExample.Utils;
using TestHelper.Attributes;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.TestTools;
Expand All @@ -30,22 +30,24 @@ public IEnumerator CreateScene_クリーンなSceneを生成してテストを
public IEnumerator LoadSceneAsync_ScenesInBuildに含まれるSceneをロードする例()
{
yield return SceneManager.LoadSceneAsync("HelloTesting");
// Scene名称指定でロードできる
// Can be load by Scene name.
// Scene名称指定でロードできます。エディター実行でもプレイヤー実行でも、同じコードで動作します。
// Can be load by Scene name. It works in both in Editor and on Player.

var cube = GameObject.Find("Cube");
Assert.That(cube, Is.Not.Null);
}

[UnityTest]
[Test]
[LoadScene("Assets/SceneExample/Scenes/NotContainScenesInBuild.unity")]
[Description("Load scene not included in the \"Scenes in Build\"")]
public IEnumerator LoadSceneAsync_ScenesInBuildに含まれていないSceneをロードする例()
public void LoadSceneAsync_ScenesInBuildに含まれていないSceneをLoadScene属性を使ってロードする例()
{
yield return TestSceneLoader.LoadSceneAsync("Assets/SceneExample/Scenes/NotContainScenesInBuild.unity");
// エディター実行・プレイヤー実行で扱いが異なる(`TestSceneLoader` 参照)
// いずれのケースでも、Assets/〜.unityまでのパスで指定が必要
// Different handling for editor and player execution. It is handled in the TestSceneLoader.
// In both cases, you need to specify the path to Assets/~.unity.
// Test Helper パッケージ(com.nowsprinting.test-helper)に含まれる LoadScene 属性は、テスト実行前に指定された Scene をロードします。
// エディター実行でもプレイヤー実行でも、同じコードで動作します。
// 『Unity Test Framework完全攻略ガイド』10.2.2 および 10.3 で紹介している方法で、エディター実行・プレイヤー実行の差異を吸収しています。

// LoadScene attribute in Test Helper package (com.nowsprinting.test-helper) loads Scene before test execution.
// It works in both in Editor and on Player.

var sphere = GameObject.Find("Sphere");
Assert.That(sphere, Is.Not.Null);
Expand Down
3 changes: 0 additions & 3 deletions Assets/SceneExample/Tests/Runtime/Utils.meta

This file was deleted.

44 changes: 0 additions & 44 deletions Assets/SceneExample/Tests/Runtime/Utils/TestSceneLoader.cs

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions SceneExample.Editor.csproj.DotSettings

This file was deleted.

0 comments on commit 86f8ab9

Please sign in to comment.