// **************************************************************** // Based on nUnit 2.6.2 (http://www.nunit.org/) // **************************************************************** using System; using System.Collections.Generic; using UnityEngine; namespace UnityTest { /// /// Summary description for ResultSummarizer. /// public class ResultSummarizer { private int m_ErrorCount; private int m_FailureCount; private int m_IgnoreCount; private int m_InconclusiveCount; private int m_NotRunnable; private int m_ResultCount; private int m_SkipCount; private int m_SuccessCount; private int m_TestsRun; private TimeSpan m_Duration; public ResultSummarizer(IEnumerable results) { foreach (var result in results) Summarize(result); } public bool Success { get { return m_FailureCount == 0; } } /// /// Returns the number of test cases for which results /// have been summarized. Any tests excluded by use of /// Category or Explicit attributes are not counted. /// public int ResultCount { get { return m_ResultCount; } } /// /// Returns the number of test cases actually run, which /// is the same as ResultCount, less any Skipped, Ignored /// or NonRunnable tests. /// public int TestsRun { get { return m_TestsRun; } } /// /// Returns the number of tests that passed /// public int Passed { get { return m_SuccessCount; } } /// /// Returns the number of test cases that had an error. /// public int Errors { get { return m_ErrorCount; } } /// /// Returns the number of test cases that failed. /// public int Failures { get { return m_FailureCount; } } /// /// Returns the number of test cases that failed. /// public int Inconclusive { get { return m_InconclusiveCount; } } /// /// Returns the number of test cases that were not runnable /// due to errors in the signature of the class or method. /// Such tests are also counted as Errors. /// public int NotRunnable { get { return m_NotRunnable; } } /// /// Returns the number of test cases that were skipped. /// public int Skipped { get { return m_SkipCount; } } public int Ignored { get { return m_IgnoreCount; } } public double Duration { get { return m_Duration.TotalSeconds; } } public int TestsNotRun { get { return m_SkipCount + m_IgnoreCount + m_NotRunnable; } } public void Summarize(ITestResult result) { m_Duration += TimeSpan.FromSeconds(result.Duration); m_ResultCount++; if(!result.Executed) { if(result.IsIgnored) { m_IgnoreCount++; return; } m_SkipCount++; return; } switch (result.ResultState) { case TestResultState.Success: m_SuccessCount++; m_TestsRun++; break; case TestResultState.Failure: m_FailureCount++; m_TestsRun++; break; case TestResultState.Error: case TestResultState.Cancelled: m_ErrorCount++; m_TestsRun++; break; case TestResultState.Inconclusive: m_InconclusiveCount++; m_TestsRun++; break; case TestResultState.NotRunnable: m_NotRunnable++; // errorCount++; break; case TestResultState.Ignored: m_IgnoreCount++; break; default: m_SkipCount++; break; } } } }