private IEnumerator RunTestUnit(UnitState testUnit) { var go = new GameObject(testUnit.unitType.ToString()); go.transform.parent = this.transform; var runner = (TestUnit)go.AddComponent(testUnit.unitType); testUnit.OnRun(runner); Application.LogCallback logReceived = (condition, stackTrace, type) => { if ((type == LogType.Error || type == LogType.Exception) && !TestHelper.UnityInternalError(condition)) { testUnit.unitCases[runner.RunningCase].failedMsg = condition; testUnit.unitCases[runner.RunningCase].failedStack = stackTrace; runner.StopTestCase(runner.RunningCase); } }; Application.logMessageReceived += logReceived; //run test cases foreach (var method in testUnit.unitCases.Keys) { var timeStarted = DateTime.Now; runner.StartTestCase(method); var state = testUnit.unitCases[method]; state.result = CaseState.Result.Run; while (runner.IsRunning) { yield return(null); } state.duration = (float)(DateTime.Now - timeStarted).TotalSeconds; state.result = state.failedMsg == null ? CaseState.Result.Success : CaseState.Result.Fail; //stopped by interruption if (!testUnit.isRunning) { break; } } yield return(new WaitForSeconds(0.5f)); Application.logMessageReceived -= logReceived; //finish test cases GameObject.Destroy(go); testUnit.OnEnd(); //output report ReportXml(testUnit); }