【发布时间】:2019-11-28 01:00:10
【问题描述】:
我刚开始使用 Unity 构建一个飞扬的恐龙游戏。因为我正在按照 TDD 理念开发我的游戏,所以我想测试我的游戏。因此,这是我在 Unity 2019.1.9.f2 上尝试做的但没有成功:
- 创建新的 2D 项目
- 在 TestRunner 中,选择 PlayMode
- 创建 PlayMode 测试程序集文件夹
- 在当前文件夹中创建测试脚本
这是我想尝试的测试代码:
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
namespace Tests
{
public class NewTestScript
{
// A Test behaves as an ordinary method
[Test]
public void NewTestScriptSimplePasses()
{
// Use the Assert class to test conditions
Assert.Inconclusive();
}
// A UnityTest behaves like a coroutine in Play Mode. In Edit Mode you can use
// `yield return null;` to skip a frame.
[UnityTest]
public IEnumerator NewTestScriptWithEnumeratorPasses()
{
// Use the Assert class to test conditions.
// Use yield to skip a frame.
yield return null;
Assert.Inconclusive();
}
}
}
TestRunner 没有向我提供任何关于测试的反馈,除了它们“没有运行”(绿色测试数 = 失败测试数 = 0,未运行测试数 = 2)。我尝试重新启动 Unity 并再次运行测试,但没有成功。
缺乏反馈很有趣,因为如果我在这两个测试中都设置了断点,那么它们就会被命中,即运行测试。
与 2018.4.3f1 和 2019.2.0b9 相同。
现在,如果我用 Unity 2018.1.9f2 重现那个实验,那么
-
NewTestScriptSimplePasses根本不提供任何反馈 -
NewTestScriptWithEnumeratorPasses在控制台中触发“InconclusiveException”
如果我用Assert.IsTrue(false) 替换Assert.Inconclusive(),那么我会在第二次测试中得到正确的反馈。如果我在第二次测试中调用Assert.IsTrue(true),那么我不会收到任何反馈。在所有情况下(还有我遇到异常的情况),测试运行器上根本不会显示绿色/红色刻度。
我做错了什么?在 EditorMode 下,一切正常。
提前感谢您的帮助...
【问题讨论】: