Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
"UnityEditor.TestRunner",
"APIExamples.Tests",
"UniTask",
"TestHelper",
"NUnit.Analyzers_Unity"
"TestHelper"
],
"includePlatforms": [
"Editor"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace APIExamples.Editor.UnityTestFramework
{
[TestFixture]
[Timeout(10000)]
public class UnityTestFrameworkVersionCheck
{
private static async UniTask<string> GetTestFrameworkPackageVersionAsync()
Expand Down
3 changes: 1 addition & 2 deletions Assets/APIExamples/Tests/Runtime/APIExamples.Tests.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
"UnityEditor.TestRunner",
"APIExamples",
"UniTask",
"TestHelper",
"NUnit.Analyzers_Unity"
"TestHelper"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
9 changes: 9 additions & 0 deletions Assets/APIExamples/Tests/Runtime/NUnit/ConstraintExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@ public void FileOrDirectoryExistsConstraint_ファイルまたはディレクト
}

[Test]
[UnityPlatform(RuntimePlatform.OSXEditor, RuntimePlatform.WindowsEditor, RuntimePlatform.LinuxEditor)]
public void HasLength_ファイルのサイズを検証()
{
var dir = Path.Combine(
Expand Down Expand Up @@ -849,8 +850,10 @@ async Task GetThrowWithMessageAsync()
throw new ArgumentException("message!");
}

#pragma warning disable UTF2002 // Ignore属性で除外した、使用できないことを示す例のため
Assert.That(async () => await GetThrowWithMessageAsync(),
Throws.TypeOf<ArgumentException>().And.Message.EqualTo("message!"));
#pragma warning restore UTF2002
// Note: 非同期(async)メソッドに対してThrows制約が使用できない
// See: https://unity3d.atlassian.net/servicedesk/customer/portal/2/IN-28107
}
Expand All @@ -865,7 +868,9 @@ async Task GetThrowWithMessageAsync()
throw new ArgumentException("message!");
}

#pragma warning disable UTF2001 // Ignore属性で除外した、使用できないことを示す例のため
Assert.ThrowsAsync<ArgumentException>(async () => await GetThrowWithMessageAsync());
#pragma warning restore UTF2001
// Note: 非同期(async)メソッドに対してThrowsAsyncも使用できない
// Note: クラシックモデルではMessage文字列の評価はできない
}
Expand Down Expand Up @@ -908,6 +913,7 @@ public void AttributeExistsConstraint_属性がつけられていること()
}

[Test]
[UnityPlatform(RuntimePlatform.OSXEditor, RuntimePlatform.WindowsEditor, RuntimePlatform.LinuxEditor)] // Has.Propertyはリフレクションでプロパティを参照し、プレイヤーではマネージドコードストリッピングで削除され得るため
public void PropertyExistsConstraint_プロパティを持っていること()
{
var actual = new 属性とプロパティ();
Expand All @@ -919,6 +925,7 @@ public void PropertyExistsConstraint_プロパティを持っていること()
}

[Test]
[UnityPlatform(RuntimePlatform.OSXEditor, RuntimePlatform.WindowsEditor, RuntimePlatform.LinuxEditor)] // Has.Propertyはリフレクションでプロパティを参照し、プレイヤーではマネージドコードストリッピングで削除され得るため
public void PropertyConstraint_プロパティの値が正しい()
{
var actual = new 属性とプロパティ();
Expand Down Expand Up @@ -1015,7 +1022,9 @@ public void DelayedConstraint_指定時間経過後に評価される()
{
var start = Time.realtimeSinceStartup; // Note: 非同期ではなく同一フレームで遅延処理されるため Time.time は変化しません

#pragma warning disable UTF2005 // realtimeSinceStartupは同一フレーム内でも進むため、DelayedConstraintでも条件が変化する
Assert.That(() => Time.realtimeSinceStartup, Is.GreaterThan(start + 0.2f).After(500));
#pragma warning restore UTF2005
// 失敗時メッセージ例:
// Expected: greater than 2.33228302f after 2500 millisecond delay
// But was: 0.33228299f
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ public class MaxTimeAttributeExample
public void MaxTime属性_指定ミリ秒よりも時間のかかるテストは実行後に失敗()
{
var endTime = DateTime.Now.AddMilliseconds(200);
#pragma warning disable UTF4003 // 同期テストでMaxTime属性の制限時間を超えさせる例のため、yieldもawaitもせずに待つ
while (DateTime.Now < endTime)
{
}
#pragma warning restore UTF4003
}

[UnityTest]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace APIExamples.NUnit
[TestFixture]
public class OrderAttributeExample
{
private static int s_count = 0;
private static int s_count;

[Test]
[Order(2)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ public class TimeoutAttributeExample
public void Timeout属性_同期テストではタイムアウトで割り込みは発生しないが終了時に指定時間を超えていたらテスト失敗()
{
var endTime = DateTime.Now.AddSeconds(0.5d);
#pragma warning disable UTF4003 // 同期テストでTimeout属性の制限時間を超えさせる例のため、yieldもawaitもせずに待つ
while (DateTime.Now < endTime)
{
}
#pragma warning restore UTF4003
}

[UnityTest]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void String型_ヒープアロケーションあり()
void UseString()
{
var s = "string";
s += s;
_ = s + s;
}

Assert.That(UseString, Is.AllocatingGCMemory());
Expand All @@ -68,7 +68,7 @@ public void Color構造体_ヒープアロケーションなし()
{
void UseColor()
{
var c = new Color(1f, 0f, 0f, 1f);
_ = new Color(1f, 0f, 0f, 1f);
}

Assert.That(UseColor, Is.Not.AllocatingGCMemory());
Expand All @@ -88,7 +88,9 @@ async Task UsePrimitives()
}
}

#pragma warning disable UTF2003 // Ignore属性で除外した、asyncメソッドでは期待どおり動作しないことを示す例のため
Assert.That(async () => await UsePrimitives(), Is.Not.AllocatingGCMemory());
#pragma warning restore UTF2003
}

[Explicit("Is.AllocatingGCMemory()をasyncメソッドに使用しても常に成功してしまう(Unity Test Framework v1.6.0時点)")]
Expand All @@ -99,10 +101,12 @@ async Task UseString()
{
await Task.Yield();
var s = "string";
s += s;
_ = s + s;
}

#pragma warning disable UTF2003 // Explicit属性で除外した、asyncメソッドでは期待どおり動作しないことを示す例のため
Assert.That(async () => await UseString(), Is.AllocatingGCMemory());
#pragma warning restore UTF2003
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using UnityEngine.TestTools;

// ReSharper disable ConditionIsAlwaysTrueOrFalse
// ReSharper disable HeuristicUnreachableCode
#pragma warning disable 162

namespace APIExamples.UnityTestFramework
Expand Down Expand Up @@ -94,6 +95,7 @@ public async Task Expect_非同期テストで先に記述_Yieldを挟んでも
}

[UnityTest]
[Timeout(1000)]
public IEnumerator Expect_非同期テストで先に記述_Yieldを挟んでも同一フレームなら有効_UnityTest()
{
LogAssert.Expect(LogType.Error, "expected message");
Expand Down Expand Up @@ -143,6 +145,7 @@ public async Task Expect_非同期テストでもログメッセージは複数
}

[UnityTest]
[Timeout(1000)]
public IEnumerator Expect_非同期テストでもログメッセージは複数フレーム有効_UnityTest()
{
Debug.Log("expected message");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ namespace BasicExample.Entities.Enums
{
public enum PassiveEffectState
{
Normal, // 通常
Normal, // 通常
Strengthening, // 強化
Weakening, // 弱体
Weakening, // 弱体
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
"UnityEngine.TestRunner",
"UnityEditor.TestRunner",
"BasicExample.Editor",
"BasicExample",
"BasicExample.Tests",
"NUnit.Analyzers_Unity"
"BasicExample",
"BasicExample.Tests"
],
"includePlatforms": [
"Editor"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace BasicExample.Editor.Validators
public class PrefabValidator
{
private static IEnumerable<TestCaseData> Prefabs => AssetDatabase
.FindAssets("t:Prefab", new string[] { "Assets/" })
.FindAssets("t:Prefab", new[] { "Assets/" })
.Select(AssetDatabase.GUIDToAssetPath)
.Select(path => new TestCaseData(path).SetName(Path.GetFileName(path)));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace BasicExample.Editor.Validators
public class SceneValidator
{
private static IEnumerable<TestCaseData> Scenes => AssetDatabase
.FindAssets("t:SceneAsset", new string[] { "Assets/" })
.FindAssets("t:SceneAsset", new[] { "Assets/" })
.Select(AssetDatabase.GUIDToAssetPath)
.Select(path => new TestCaseData(path).SetName(Path.GetFileName(path)));

Expand Down
5 changes: 2 additions & 3 deletions Assets/BasicExample/Tests/Runtime/BasicExample.Tests.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
"references": [
"UnityEngine.TestRunner",
"UnityEditor.TestRunner",
"BasicExample",
"TestHelper",
"NUnit.Analyzers_Unity"
"BasicExample",
"TestHelper"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void IsDestroyed_もう死んでいる()
public void TakeDamage_防御力3に対して攻撃力1_ダメージなし()
{
// Setup
var sut = new CharacterStatus(Element.None, defense: 3);
var sut = new CharacterStatus(defense: 3);

// Exercise
var damage = sut.TakeDamage(Element.None, attack: 1);
Expand All @@ -45,7 +45,7 @@ public void TakeDamage_防御力3に対して攻撃力1_HP減少なし()
{
// Setup
var beforeHp = 100;
var sut = new CharacterStatus(Element.None, defense: 3, hp: beforeHp);
var sut = new CharacterStatus(defense: 3, hp: beforeHp);

// Exercise
sut.TakeDamage(Element.None, attack: 1);
Expand All @@ -58,7 +58,7 @@ public void TakeDamage_防御力3に対して攻撃力1_HP減少なし()
[Test]
public void TakeDamage_防御力0に対して攻撃力1_ダメージあり()
{
var sut = new CharacterStatus(Element.None, defense: 0);
var sut = new CharacterStatus(defense: 0);

var damage = sut.TakeDamage(Element.None, attack: 1);

Expand All @@ -69,7 +69,7 @@ public void TakeDamage_防御力0に対して攻撃力1_ダメージあり()
public void TakeDamage_防御力2に対して攻撃力3_HPが1減少()
{
var beforeHp = 100;
var sut = new CharacterStatus(Element.None, defense: 2, hp: beforeHp);
var sut = new CharacterStatus(defense: 2, hp: beforeHp);

sut.TakeDamage(Element.None, attack: 3);

Expand All @@ -82,7 +82,7 @@ public void TakeDamage_防御力2に対して攻撃力3_HPが1減少()
public void TakeDamage_防御力より攻撃力が大きい_HPが差分だけ減少(int defence, int attackPower, int expected)
{
var beforeHp = 100;
var sut = new CharacterStatus(Element.None, defense: defence, hp: beforeHp);
var sut = new CharacterStatus(defense: defence, hp: beforeHp);

sut.TakeDamage(Element.None, attack: attackPower);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class 同値分割法に基づいたテスト
public void GetHitPointGaugeColor_HP残量に対する表示色は正しい(float percentage, Color expected)
{
var sut = ScriptableObject.CreateInstance<HitPointGaugeSetting>();
var actual = sut.GetHitPointGaugeColor(percentage, false);
var actual = sut.GetHitPointGaugeColor(percentage);

Assert.That(actual, Is.EqualTo(expected).Using(ColorEqualityComparer.Instance));
}
Expand All @@ -49,7 +49,7 @@ public class 境界値分析に基づいたテスト
public void GetHitPointGaugeColor_HP残量に対する表示色は正しい(float percentage, Color expected)
{
var sut = ScriptableObject.CreateInstance<HitPointGaugeSetting>();
var actual = sut.GetHitPointGaugeColor(percentage, false);
var actual = sut.GetHitPointGaugeColor(percentage);

Assert.That(actual, Is.EqualTo(expected).Using(ColorEqualityComparer.Instance));
}
Expand Down
12 changes: 11 additions & 1 deletion Assets/Default.globalconfig
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
is_global = true

# CS0618: Type or member is obsolete
dotnet_diagnostic.CS0618.severity = error
dotnet_diagnostic.VSTHRD200.severity = suggestion

# UTF2006: Property constraints, Ordered.By, and List.Map(...).Property lookup properties that managed code stripping can remove
dotnet_diagnostic.UTF2006.severity = warning

# UTF4004-UTF4007: Recommendations against fixed-time waits and coroutine-style tests; this project demonstrates those APIs
dotnet_diagnostic.UTF4004.severity = suggestion
dotnet_diagnostic.UTF4005.severity = suggestion
dotnet_diagnostic.UTF4006.severity = suggestion
dotnet_diagnostic.UTF4007.severity = suggestion
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class FirstPersonControllerLegacy : MonoBehaviour
private float rotateSpeed = 30.0f;

private const float Gravity = -9.81f;
private float _yVelocity = 0f;
private float _yVelocity;

// UnityEngine.Inputの代わりにInputWrapperを使用する
internal IInput Input { private get; set; } = new InputWrapper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class FirstPersonController : MonoBehaviour
private float rotateSpeed = 30.0f;

private const float Gravity = -9.81f;
private float _yVelocity = 0f;
private float _yVelocity;

private void Awake()
{
Expand Down
2 changes: 1 addition & 1 deletion Assets/InputSystemExample/Scripts/Runtime/GoalPlate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace InputSystemExample
[RequireComponent(typeof(Collider))]
public class GoalPlate : MonoBehaviour
{
public bool IsGoal { get; private set; } = false;
public bool IsGoal { get; private set; }

private void OnTriggerEnter(Collider other)
{
Expand Down
3 changes: 2 additions & 1 deletion Assets/InputSystemExample/Tests/Runtime/ScenarioTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class ScenarioTest
private const string InputTracesPath = "Assets/InputSystemExample/Tests/InputTraces";

[TestCase("Keyboard.inputtrace")]
[Timeout(30000)]
public async Task PlaybackTesting_ゴールに到達すること(string path)
{
// フレームレートをキャプチャ環境に合わせる(Updateで入力を処理しているとき必要)
Expand All @@ -47,7 +48,7 @@ public async Task PlaybackTesting_ゴールに到達すること(string path)

var isFinished = false;

using (var replayController = eventTrace.Replay()
using (eventTrace.Replay()
.OnFinished(() => { isFinished = true; }) // 再生終了したらフラグを立てる
.PlayAllEventsAccordingToTimestamps())
{
Expand Down
4 changes: 4 additions & 0 deletions Assets/SceneExample/Tests/Runtime/ResourcesExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public void Cleanup()
[Test]
public void Load_プレイヤー実行でPrefabをロードして使用する例()
{
// IPrebuildSetupでビルド時に生成するResourcesのため、プロジェクト上には存在しない
// ReSharper disable once Unity.UnknownResource
var prefab = Resources.Load<GameObject>("Prefabs/PrefabExample");
// ビルド時に生成するResourcesからのパス、拡張子なし

Expand All @@ -59,6 +61,8 @@ public void Load_プレイヤー実行でPrefabをロードして使用する例
[Test]
public void Load_プレイヤー実行でテキストファイルをロードして使用する例()
{
// IPrebuildSetupでビルド時に生成するResourcesのため、プロジェクト上には存在しない
// ReSharper disable once Unity.UnknownResource
var text = Resources.Load<TextAsset>("TextAssets/TextExample");
// ビルド時に生成するResourcesからのパス、拡張子なし

Expand Down
2 changes: 1 addition & 1 deletion Assets/TestDoubleExample/Scripts/Runtime/Janken/Hand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ public enum Hand
{
Rock = 0, // ぐー
Scissors, // ちょき
Paper // ぱー
Paper // ぱー
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ public void Pon_PRNGのRangeに要求している値域は0から1であるこ

spy.Received().Range(0.0f, 1.0f); // 引数 (0f, 1f) で呼ばれたことを検証
spy.DidNotReceive().Range(Arg.Is<float>(x => x != 0.0f), Arg.Any<float>()); // 第一引数は 0f 以外では呼ばれていないことを検証
// 引数に渡されたリテラル値そのものかを検証するため、誤差を許容しない
// ReSharper disable once CompareOfFloatsByEqualityOperator
spy.DidNotReceive().Range(Arg.Any<float>(), Arg.Is<float>(x => x != 1.0f)); // 第二引数は 1f 以外では呼ばれていないことを検証
}
}
Expand Down
Loading
Loading