gpt4 book ai didi

unity-game-engine - PlayMode 中的 Unity3D Test Runner 不提供测试反馈

转载 作者:行者123 更新时间:2023-11-28 20:48:21 24 4
gpt4 key购买 nike

我刚开始使用 Unity 构建一个飞扬的恐龙游戏。因为我正在按照 TDD 理念开发我的游戏,所以我想测试我的游戏。因此,这是我在 Unity 2019.1.9.f2 上尝试但没有成功的尝试:

  1. 创建新的 2D 项目
  2. 在 TestRunner 中,选择 PlayMode
  3. 创建 PlayMode 测试程序集文件夹
  4. 在当前文件夹中创建测试脚本

这是我想尝试的测试代码:

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.Inconclusive() 替换为 Assert.IsTrue(false),那么我会在第二次测试中得到正确的反馈。如果我在第二次测试中调用 Assert.IsTrue(true),那么我不会得到任何反馈。在所有情况下(也包括我遇到异常的情况),测试运行器上根本不显示绿色/红色勾号。

我做错了什么?在 EditorMode 中,一切正常。

预先感谢您的帮助...

最佳答案

所以......我终于能够让它发挥作用。在我看来,这可能是 Unity 中的一个错误,但我不能自信地说,因为我是一个非常缺乏经验的 Unity 用户。这是我如何获得绿色/红色勾号的方法:完全巧合,我按下了播放按钮(玩游戏,所以与测试无关),然后按下暂停,然后再次按下暂停,然后按下步骤按钮。同时,在 2018.4.3f1 版本中,我能够运行 PlayMode 测试。然后,突然出现了绿色/红色的勾号。从那时起,我不再需要在播放模式下运行我的游戏来获得关于我的测试的反馈……这有点奇怪。此外,不确定的断言没有被正确跟踪:有被认为是通过的,它们应该被视为与在 EditorMode 中相同的方式:不确定的,橙色圆圈。

关于unity-game-engine - PlayMode 中的 Unity3D Test Runner 不提供测试反馈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57105569/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com