Initial Commit
This commit is contained in:
parent
53eb92e9af
commit
270ab7d11f
15341 changed files with 700234 additions and 0 deletions
|
@ -0,0 +1,11 @@
|
|||
namespace UnityEngine.TestTools
|
||||
{
|
||||
/// <summary>
|
||||
/// An interface implemented by a MonoBehaviour test.
|
||||
/// </summary>
|
||||
public interface IMonoBehaviourTest
|
||||
{
|
||||
/// <summary>True when the test is considered finished.</summary>
|
||||
bool IsTestFinished {get; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a002d3737b873954395b7cf862873ab8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,60 @@
|
|||
namespace UnityEngine.TestTools
|
||||
{
|
||||
/// <summary>
|
||||
/// This is a wrapper that allows running tests on MonoBehaviour scripts. Inherits from <see cref="CustomYieldInstruction"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">A MonoBehaviour component created for the test and attached to the tests [GameObject](https://docs.unity3d.com/ScriptReference/GameObject.html).</typeparam>
|
||||
public class MonoBehaviourTest<T> : CustomYieldInstruction where T : MonoBehaviour, IMonoBehaviourTest
|
||||
{
|
||||
/// <summary>A MonoBehaviour component created for the test and attached to the tests [GameObject](https://docs.unity3d.com/ScriptReference/GameObject.html).</summary>
|
||||
public T component { get; }
|
||||
/// <summary>
|
||||
/// A `GameObject` created as a container for the test component.
|
||||
/// </summary>
|
||||
public GameObject gameObject { get { return component.gameObject; } }
|
||||
/// <summary>
|
||||
/// `MonoBehaviourTest` is a [coroutine](https://docs.unity3d.com/ScriptReference/Coroutine.html) and a helper for writing MonoBehaviour tests.
|
||||
/// Yield a `MonoBehaviour`Test 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.
|
||||
/// </summary>
|
||||
/// <param name="dontDestroyOnLoad"></param>
|
||||
/// <example>
|
||||
/// <code>
|
||||
/// [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++;
|
||||
/// }
|
||||
/// }
|
||||
/// </code>
|
||||
/// </example>
|
||||
public MonoBehaviourTest(bool dontDestroyOnLoad = true)
|
||||
{
|
||||
var go = new GameObject("MonoBehaviourTest: " + typeof(T).FullName);
|
||||
component = go.AddComponent<T>();
|
||||
if (dontDestroyOnLoad)
|
||||
{
|
||||
Object.DontDestroyOnLoad(go);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// (Inherited) Returns `true`` if the test is not finished yet, which keeps the coroutine suspended
|
||||
/// </summary>
|
||||
public override bool keepWaiting
|
||||
{
|
||||
get { return !component.IsTestFinished; }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 164c9b1458eaab743a4b45c37a4d720d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue