[Test]
public void GameObject_CreatedWithGiven_WillHaveTheName()
{
//一条龙直接往下的
var go = new GameObject("MyGameObject");
Assert.AreEqual("MyGameObject", go.name);
}
[UnityTest]
public IEnumerator TestMono()
{
//需要等待
yield return new MonoBehaviourTest<MonoSSS>();
}
public class MonoSSS : MonoBehaviour,IMonoBehaviourTest
{
public bool IsTestFinished
{
get
{
if (index == 100) return true;
return false;
}
}
int index = 0;
void Update()
{
index++;
}
}Test的测试方法是挺简单的,一般就是将对应需要测试的类实例化一下,然后调用你要测试的方法,最后Assert断言验证数据的正确性。
UnityTest测试的是一个MonoBehaviour的脚本,MonoBehaviourTest返回的是一个IEnumerator,然后等待MonoBehaviour测试的完成。
怎么识别MonoBehaviour脚本测试的完成,就是实现IMonoBehaviourTest接口的IsTestFinished,返回true就表示测试完了。