public void TestRun() { m_test.SetTestMethod("TestMethod"); TestResult res1 = new TestResult(); TestResult res2 = m_test.Run(res1); Assert.NotNull(res2); Assert.Equal(res1, res2); }
/** * Run the test, catching all exceptions. * * @param result, the result of the test. * * @return TestResult, the result of the test. */ public IEnumerator Run(TestResult result) { // If test method invalid if (null == m_testMethod) { // Error throw new Exception("Invalid test method encountered, be sure to call " + "TestCase::SetTestMethod()"); } // If the test method does not exist Type type = GetType(); MethodInfo method = type.GetMethod(m_testMethod); if (null == method) { // Error throw new Exception("Test method: " + m_testMethod + " does not exist in class: " + type.ToString()); } // If result invalid if (null == result) { // Create result result = new TestResult(); } // Pre-test setup SetUp(); result.TestStarted(); yield return StartCoroutine((IEnumerator)method.Invoke(this, null)); if (_Exception != null) { result.TestFailed(_Exception); UnityEngine.Debug.LogWarning("[SharpUnit] " + type.Name + "." + method.Name + " failed"); } else if (_Failed) { result.TestFailed(new TestException("DoneTesting for " + type.Name + "." + method.Name + " not called.")); UnityEngine.Debug.LogWarning("[SharpUnit] " + type.Name + "." + method.Name + " might be failed"); } else { UnityEngine.Debug.Log("[SharpUnit] " + type.Name + "." + method.Name + " runs ok"); } // Clear expected exception Assert.Exception = null; // Post-test cleanup TearDown(); _TestResult = result; }
/** * Run all of the tests in the test suite. * * @param result, result of the test run. */ public TestResult Run(TestResult result) { // For each test foreach (TestCase test in m_tests) { // Run test result = test.Run(result); } // Return results return result; }
/** * Outputs the results of the unit tests. * * @param result, the result containing the failures to display. */ public virtual void LogResults(TestResult result) { // Set results m_result = result; // Log summary LogSummary(); // If results valid if (null != m_result) { // For each failure foreach (Exception error in m_result.ErrorList) { // Log the failure LogFailure(error); } } }
public override void TearDown() { m_res = null; }
private TestResult m_res = null; // TestResult instance for testing #endregion Fields #region Methods public override void SetUp() { m_res = new TestResult(); }
protected string m_testMethod = null; // Name of the test method to run. #endregion Fields #region Methods /** * Run the test, catching all exceptions. * * @param result, the result of the test. * * @return TestResult, the result of the test. */ public virtual TestResult Run(TestResult result) { // If test method invalid if (null == m_testMethod) { // Error throw new Exception("Invalid test method encountered, be sure to call TestCase::SetTestMethod()"); } // If the test method does not exist Type type = GetType(); MethodInfo method = type.GetMethod(m_testMethod); if (null == method) { // Error throw new Exception("Test method: " + m_testMethod + " does not exist in class: " + type.ToString()); } // If result invalid if (null == result) { // Create result result = new TestResult(); } // Pre-test setup SetUp(); result.TestStarted(); try { try { // Try to call the test method method.Invoke(this, null); } catch (TargetInvocationException e) { // If we are expecting an exception m_caughtEx = e; if (null != Assert.Exception) { // Compare the exceptions Assert.Equal(Assert.Exception, m_caughtEx.InnerException); } else { // If this is a test exception if (null != e.InnerException && typeof(TestException) == e.InnerException.GetType()) { // Set the description TestException te = e.InnerException as TestException; te.Description = "Failed: " + GetType() + "." + m_testMethod + "()"; if (null != te.StackFrame) { // Add stack frame info te.Description += " in File: " + System.IO.Path.GetFileName( te.StackFrame.GetFileName() ); te.Description += " on Line: " + te.StackFrame.GetFileLineNumber(); } } // Re-throw the exception to be tracked throw m_caughtEx.InnerException; } } // If we are expecting an exception but did not catch one if (null != Assert.Exception && null == m_caughtEx) { // Error Assert.NotNull(m_caughtEx, "Did not catch expected exception: " + Assert.Exception); } } catch (Exception ex) { // Track test failure result.TestFailed( ex ); } // Clear expected exception Assert.Exception = null; // Post-test cleanup TearDown(); return result; }
/** * Run the test, catching all exceptions. * * @param result, the result of the test. * * @return TestResult, the result of the test. */ public TestResult Run(TestResult result) { // If test method invalid if (null == m_testMethod) { // Error throw new Exception("Invalid test method encountered, be sure to call TestCase::SetTestMethod()"); } // If the test method does not exist Type type = GetType(); MethodInfo method = type.GetMethod(m_testMethod); if (null == method) { // Error throw new Exception("Test method: " + m_testMethod + " does not exist in class: " + type.ToString()); } // If result invalid if (null == result) { // Create result result = new TestResult(); } // Pre-test setup SetUp(); result.TestStarted(); try { try { // Try to call the test method method.Invoke(this, null); } catch (TargetInvocationException e) { // If we are expecting an exception m_caughtEx = e; if (null != Assert.Exception) { // Compare the exceptions Assert.Equal(Assert.Exception, m_caughtEx.InnerException); } else { // If this is a test exception if (null != e.InnerException && typeof(TestException) == e.InnerException.GetType()) { // Set the description TestException te = e.InnerException as TestException; te.Description = "Failed: " + GetType() + "." + m_testMethod + "()"; if (null != te.StackFrame) { // Add stack frame info te.Description += " in File: " + System.IO.Path.GetFileName(te.StackFrame.GetFileName()); te.Description += " on Line: " + te.StackFrame.GetFileLineNumber(); } } // Re-throw the exception to be tracked throw m_caughtEx.InnerException; } } // If we are expecting an exception but did not catch one if (null != Assert.Exception && null == m_caughtEx) { // Error Assert.NotNull(m_caughtEx, "Did not catch expected exception: " + Assert.Exception); } } catch (Exception ex) { // Track test failure result.TestFailed(ex); } // Clear expected exception Assert.Exception = null; // Post-test cleanup TearDown(); return(result); }