我正在使用 Unity 测试工具框架。我的单元测试代码看起来像这样(包括更多)
[TestFixture]
public class ActionMasterTester: MonoBehaviour{
private ActionMaster actionMaster;
[SetUp]
public void SetUp()
{
actionMaster = new ActionMaster();
}
}
Run Code Online (Sandbox Code Playgroud)
ActionMaster 看起来像这样:
public class ActionMaster : MonoBehaviour {
}
Run Code Online (Sandbox Code Playgroud)
如果我运行测试,那么我会收到以下警告 actionMaster = new ActionMaster();
You are trying to create a MonoBehaviour using the 'new' keyword. This is not allowed. MonoBehaviours can only be added using AddComponent(). Alternatively, your script can inherit from ScriptableObject or no base class at all
UnityEngine.MonoBehaviour:.ctor()
ActionMaster:.ctor()
ActionMasterTester:SetUp() (at Assets/Editor/ActionMasterTester.cs:21)
System.Reflection.MethodBase:Invoke(Object, Object[])
NUnit.Core.Reflect:InvokeMethod(MethodInfo, Object, …Run Code Online (Sandbox Code Playgroud)