【发布时间】:2021-09-11 16:33:32
【问题描述】:
我的 Unity 项目有 EditMode 单元测试:
[Test]
public async void TestGetHeroAssetResult()
{
var guid = Guid.Parse("123");
var result = await sut.GetHeroAsset(guid);
Assert.AreEqual(result.AssetType, "type1");
}
运行时抛出异常:
FormatException: Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).
我当然可以修复它。但问题是测试结果是SUCCESS。
这是 Unity 测试的正常行为吗?如何在异常情况下强制此测试失败?统一版:2020.3.2f1。我是 Unity 的新手,感谢任何帮助!
【问题讨论】:
-
也许您必须将测试的签名更改为
public async Task TestGetHeroAssetResult() -
谢谢,它帮助我通过了测试。但是现在它每次都失败了,即使它应该成功。对于所有遇到此问题的人,我在 Unity 中找到了有关异步测试的有用主题,请查看 forum.unity.com/threads/async-await-in-unittests.513857
-
我对统一测试框架了解不多,但现代版本的 MsTest 和 Nunit 能够毫无问题地处理异步测试。
-
Unity 测试框架使用 NUnit 3.5,根据它的异步特性,它应该像你说的那样工作。但是每次我使用
async Task返回类型运行测试时,我都会得到:Method has non-void return value, but no result is expected
标签: c# unit-testing unity3d