Assignment for RMIT Mixed Reality in 2020
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.

61 lines
1.8 KiB

  1. namespace VRTK.Examples.Tests
  2. {
  3. using UnityEngine;
  4. using System.Collections;
  5. public abstract class VRTK_BaseTest : MonoBehaviour
  6. {
  7. protected string currentTest;
  8. protected string currentSetup;
  9. protected abstract void Test();
  10. protected virtual void OnEnable()
  11. {
  12. StartCoroutine(RunTests());
  13. }
  14. protected virtual void BeginTest(string name, int level = 1)
  15. {
  16. currentTest = name;
  17. Debug.Log("<color=darkblue><b>" + "".PadLeft(level, '#') + " Starting Tests for " + name + "</b></color>");
  18. }
  19. protected virtual void SetUp(string message)
  20. {
  21. currentSetup = message;
  22. Debug.Log("<color=blue><b>#### Preparing test for " + message + "</b></color>");
  23. }
  24. protected virtual void TearDown()
  25. {
  26. Debug.Log("==============================================================================");
  27. }
  28. protected virtual void Assert(string description, bool assertion, string failure, string success = "")
  29. {
  30. if (assertion)
  31. {
  32. Debug.Log("<color=teal><b>## [" + description + "] PASSED ##</b></color>");
  33. }
  34. else
  35. {
  36. Debug.Log("<color=maroon><b>## [" + description + "] FAILED INSIDE [" + currentTest + "." + currentSetup + "]##</b></color>");
  37. }
  38. if (!assertion)
  39. {
  40. Debug.LogException(new System.Exception(failure));
  41. }
  42. else if (success != "")
  43. {
  44. Debug.Log("<color=purple><i> ~~~~~> " + success + "</i></color>");
  45. }
  46. }
  47. protected virtual IEnumerator RunTests()
  48. {
  49. yield return new WaitForEndOfFrame();
  50. Test();
  51. }
  52. }
  53. }