-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAsyncSetupAttributeExample.cs
More file actions
57 lines (51 loc) · 1.79 KB
/
AsyncSetupAttributeExample.cs
File metadata and controls
57 lines (51 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright (c) 2021-2025 Koji Hasegawa.
// This software is released under the MIT License.
using System.Collections;
using System.Threading.Tasks;
using NUnit.Framework;
using UnityEngine.TestTools;
namespace APIExamples.Editor.NUnit
{
/// <summary>
/// 非同期の<see cref="SetUpAttribute"/>の使用例(Edit Modeテスト)
/// <see cref="OneTimeSetUpAttribute"/>はasyncサポートされていない(UTF v1.6.0時点)
/// <p/>
/// Async SetUp attribute example (in Edit Mode tests)
/// Async OneTimeSetUp attribute is not yet supported in UTF v1.6.0
/// </summary>
/// <remarks>
/// Required: Unity Test Framework v1.3 or later
/// </remarks>
/// <seealso cref="APIExamples.Editor.UnityTestFramework.UnitySetUpAttributeExample"/>
[TestFixture]
public class AsyncSetupAttributeExample
{
private int _setupCount;
/// <summary>
/// 各テストメソッドの前に実行されます
/// </summary>
[SetUp]
public async Task SetUpAsync()
{
await Task.Yield();
_setupCount++;
}
[Test, Order(0)]
public void TestMethod()
{
Assert.That(_setupCount, Is.EqualTo(1), "最初のテストなのでSetUpは1回実行されている");
}
[Test, Order(1)]
public async Task TestMethodAsync()
{
await Task.Yield();
Assert.That(_setupCount, Is.EqualTo(2), "2番目のテストなのでSetUpは2回実行されている");
}
[UnityTest, Order(2)]
public IEnumerator UnityTestMethod()
{
yield return null;
Assert.That(_setupCount, Is.EqualTo(3), "3番目のテストなのでSetUpは3回実行されている");
}
}
}