Unity:PlayMode UnityTest和EditMode UnityTest有什么区别? [英] Unity: What's the difference between a PlayMode UnityTest and an EditMode UnityTest?
问题描述
我正在尝试学习如何在Unity3D中编写测试,但文档很少
I'm trying to learn how to write tests in Unity3D, but the documentation is sparse.
您可以在PlayMode或EditMode测试中都使用[UnityTest]
,但是我不了解选择其中一项的重要性.我认为在PlayMode中,它实际上可以运行您的游戏,但我仍然不明白为什么我会或不想这样做.
You can use [UnityTest]
on both PlayMode or EditMode tests, but I don't understand the significance in choosing one over the other. I think in PlayMode, it actually runs your game, but I still don't understand why I would or would not want that.
推荐答案
实际上很简单:
检查不需要播放模式的任何内容(Update
,Awake
,Start
等),或者必须在输入之前进行显式测试.例如
Check anything that doesn't require PlayMode (Update
, Awake
, Start
etc) or that has to be tested explicitly before entering it. E.g.
- 场景中是否有
Camera
? - 用于混合现实:播放模式开始之前,相机是否位于位置
0, 0, 0
? - 相机是否具有
PhysicsRaycaster
组件以使IPointerXxx
界面正常工作
- is there a
Camera
in the Scene? - for mixed reality: is the Camera at position
0, 0, 0
before the playmode starts? - does the Camera have a
PhysicsRaycaster
component to makeIPointerXxx
interfaces work
对于某些游戏,在进入PlayMode之前必须对其进行测试,而对于其他方法,该方法只是速度更快,因为它无需在场景中初始化所有内容即可测试一项特定的内容
For some it is necessary to test them before entering PlayMode, for the rest this method is simply faster since it doesn't have to initialize everything in your Scene before being able to test one specific thing.
检查需要运行时的脚本(Update
,FixedUpdate
等),已初始化的所有内容(已执行Awake
,Start
等)或物理操作,例如
Check scripts that require runtime (Update
, FixedUpdate
, etc), everything initialized (executed Awake
, Start
, etc) or physics e.g.
- 此对象是否将在访问它们之前初始化所有组件?
- 此
while
循环会在给定时间内终止吗? - 我看到的最好的物理示例是有关物理材料的:如果将蹦蹦跳跳"设置为
0.99
,球会在X秒后停止跳动吗?
- will this object have all components initialized before accessing them?
- will this
while
loop terminate (within a given time)? - the best physics example I saw was about Physics materials: If bounciness is set to
0.99
will the ball stop jumping after X seconds?
这篇关于Unity:PlayMode UnityTest和EditMode UnityTest有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!