using NUnit.Framework; using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Reflection; using UnityEngine; using UnityEngine.Events; using UnityEngine.TestTools; using UnityEngine.UI; namespace RuntimeUnitTestToolkit { public class UnitTestRunner : MonoBehaviour { // object is IEnumerator or Func Dictionary>> tests = new Dictionary>>(); List additionalActionsOnFirst = new List(); public Button clearButton; public RectTransform list; public Scrollbar listScrollBar; public Text logText; public Scrollbar logScrollBar; readonly Color passColor = new Color(0f, 1f, 0f, 1f); // green readonly Color failColor = new Color(1f, 0f, 0f, 1f); // red readonly Color normalColor = new Color(1f, 1f, 1f, 1f); // white bool allTestGreen = true; void Start() { try { UnityEngine.Application.logMessageReceived += (a, b, c) => { logText.text += "[" + c + "]" + a + "\n"; }; // register all test types foreach (var item in GetTestTargetTypes()) { RegisterAllMethods(item); } var executeAll = new List>(); foreach (var ___item in tests) { var actionList = ___item; // be careful, capture in lambda executeAll.Add(() => StartCoroutine(RunTestInCoroutine(actionList))); Add(actionList.Key, () => StartCoroutine(RunTestInCoroutine(actionList))); } var executeAllButton = Add("Run All Tests", () => StartCoroutine(ExecuteAllInCoroutine(executeAll))); clearButton.gameObject.GetComponent().color = new Color(170 / 255f, 170 / 255f, 170 / 255f, 1); executeAllButton.gameObject.GetComponent().color = new Color(250 / 255f, 150 / 255f, 150 / 255f, 1); executeAllButton.transform.SetSiblingIndex(1); additionalActionsOnFirst.Reverse(); foreach (var item in additionalActionsOnFirst) { var newButton = GameObject.Instantiate(clearButton); newButton.name = item.Name; newButton.onClick.RemoveAllListeners(); newButton.GetComponentInChildren().text = item.Name; newButton.onClick.AddListener(item.Action); newButton.transform.SetParent(list); newButton.transform.SetSiblingIndex(1); } clearButton.onClick.AddListener(() => { logText.text = ""; foreach (var btn in list.GetComponentsInChildren