SW 중심대학 OSS GIT 서버 박건태, 이승준, 고기완, 이준호 새로운 배포
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
2.0 KiB

4 years ago
  1. # MonoBehaviour tests
  2. `MonoBehaviourTest` is a [coroutine](https://docs.unity3d.com/ScriptReference/Coroutine.html) and a helper for writing [MonoBehaviour](https://docs.unity3d.com/ScriptReference/MonoBehaviour.html) tests.
  3. 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.
  4. ## Example
  5. ```c#
  6. [UnityTest]
  7. public IEnumerator MonoBehaviourTest_Works()
  8. {
  9. yield return new MonoBehaviourTest<MyMonoBehaviourTest>();
  10. }
  11. public class MyMonoBehaviourTest : MonoBehaviour, IMonoBehaviourTest
  12. {
  13. private int frameCount;
  14. public bool IsTestFinished
  15. {
  16. get { return frameCount > 10; }
  17. }
  18. void Update()
  19. {
  20. frameCount++;
  21. }
  22. }
  23. ```
  24. ## MonoBehaviourTest&lt;T&gt;
  25. This is a wrapper that allows running tests on `MonoBehaviour` scripts. Inherits from [CustomYieldInstruction](https://docs.unity3d.com/ScriptReference/CustomYieldInstruction.html).
  26. ### Properties
  27. | Syntax | Description |
  28. | ----------------------- | ------------------------------------------------------------ |
  29. | `T component` | A `MonoBehaviour` component created for the test and attached to the test’s [GameObject](https://docs.unity3d.com/ScriptReference/GameObject.html). |
  30. | `GameObject gameObject` | A `GameObject` created as a container for the test component. |
  31. | `bool keepWaiting` | (Inherited) Returns `true` if the test is not finished yet, which keeps the coroutine suspended. |
  32. ## IMonoBehaviourTest
  33. An interface implemented by a `MonoBehaviour` test.
  34. ### Properties
  35. | Syntax | Description |
  36. | --------------------- | ----------------------------------------------- |
  37. | `bool IsTestFinished` | Indicates when the test is considered finished. |