Class MonoBehaviourTest<T>
This is a wrapper that allows running tests on MonoBehaviour scripts. Inherits from CustomYieldInstruction.
Implements
Inherited Members
Namespace: UnityEngine.TestTools
Assembly: UnityEngine.TestRunner.dll
Syntax
public class MonoBehaviourTest<T> : CustomYieldInstruction, IEnumerator where T : MonoBehaviour, IMonoBehaviourTest
Type Parameters
| Name | Description |
|---|---|
| T | A MonoBehaviour component created for the test and attached to the tests GameObject. |
Constructors
MonoBehaviourTest(bool)
MonoBehaviourTest is a coroutine and a helper for writing MonoBehaviour tests.
Yield a MonoBehaviourTest when using the UnityTest attribute to instantiate the MonoBehaviour you wish to test and wait for it to finish running. Implement the IMonoBehaviourTest interface on the MonoBehaviour to state when the test completes.
Declaration
public MonoBehaviourTest(bool dontDestroyOnLoad = true)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | dontDestroyOnLoad |
Examples
[UnityTest]
public IEnumerator MonoBehaviourTest_Works()
{
yield return new MonoBehaviourTest<MyMonoBehaviourTest>();
}
public class MyMonoBehaviourTest : MonoBehaviour, IMonoBehaviourTest
{
private int frameCount;
public bool IsTestFinished
{
get { return frameCount > 10; }
}
void Update()
{
frameCount++;
}
}
Properties
component
A MonoBehaviour component created for the test and attached to the tests GameObject.
Declaration
public T component { get; }
Property Value
| Type | Description |
|---|---|
| T |
gameObject
A GameObject created as a container for the test component.
Declaration
public GameObject gameObject { get; }
Property Value
| Type | Description |
|---|---|
| GameObject |
keepWaiting
(Inherited) Returns `true`` if the test is not finished yet, which keeps the coroutine suspended
Declaration
public override bool keepWaiting { get; }
Property Value
| Type | Description |
|---|---|
| bool |