public void Run(UUnitTestResult testResult) { UUnitTestResult.TestState testState = UUnitTestResult.TestState.FAILED; string message = null; eachTestStopwatch.Reset(); setUpStopwatch.Reset(); tearDownStopwatch.Reset(); try { testResult.TestStarted(); setUpStopwatch.Start(); SetUp(); setUpStopwatch.Stop(); Type type = this.GetType(); MethodInfo method = type.GetRuntimeMethod(testMethodName, EMPTY_PARAMETER_TYPES); // Test methods must contain no parameters UUnitAssert.NotNull(method, "Could not execute: " + testMethodName + ", it's probably not public."); // Limited access to loaded assemblies eachTestStopwatch.Start(); ((UUnitTestDelegate)method.CreateDelegate(typeof(UUnitTestDelegate), this))(); // This creates a delegate of the test function, and calls it testState = UUnitTestResult.TestState.PASSED; } catch (UUnitAssertException e) { message = e.ToString(); testState = UUnitTestResult.TestState.FAILED; } catch (UUnitSkipException) { // message remains null testState = UUnitTestResult.TestState.SKIPPED; } catch (TargetInvocationException e) { message = e.InnerException.ToString(); testState = UUnitTestResult.TestState.FAILED; } catch (Exception e) { message = e.ToString(); testState = UUnitTestResult.TestState.FAILED; } finally { eachTestStopwatch.Stop(); if (testState != UUnitTestResult.TestState.SKIPPED) { try { tearDownStopwatch.Start(); TearDown(); tearDownStopwatch.Stop(); } catch (Exception e) { message = e.ToString(); testState = UUnitTestResult.TestState.FAILED; } } } testResult.TestComplete(testMethodName, testState, eachTestStopwatch.ElapsedMilliseconds, message); }
public void Run(UUnitTestResult testResult) { UUnitTestResult.TestState testState = UUnitTestResult.TestState.FAILED; string message = null; eachTestStopwatch.Reset(); setUpStopwatch.Reset(); tearDownStopwatch.Reset(); try { testResult.TestStarted(); setUpStopwatch.Start(); SetUp(); setUpStopwatch.Stop(); Type type = this.GetType(); MethodInfo method = type.GetMethod(testMethodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); UUnitAssert.NotNull(method, "Could not execute: " + testMethodName + ", it's probably not public."); // Limited access to loaded assemblies eachTestStopwatch.Start(); method.Invoke(this, null); testState = UUnitTestResult.TestState.PASSED; } catch (UUnitSkipException) { // message remains null testState = UUnitTestResult.TestState.SKIPPED; } catch (UUnitAssertException e) { message = e.ToString(); testState = UUnitTestResult.TestState.FAILED; } catch (TargetInvocationException e) { if (e.InnerException is UUnitSkipException) { // message remains null testState = UUnitTestResult.TestState.SKIPPED; } else { message = e.InnerException.ToString(); testState = UUnitTestResult.TestState.FAILED; } } catch (Exception e) { message = e.ToString(); testState = UUnitTestResult.TestState.FAILED; } finally { eachTestStopwatch.Stop(); if (testState != UUnitTestResult.TestState.SKIPPED) { try { tearDownStopwatch.Start(); TearDown(); tearDownStopwatch.Stop(); } catch (Exception e) { message = e.ToString(); testState = UUnitTestResult.TestState.FAILED; } } } testResult.TestComplete(testMethodName, testState, eachTestStopwatch.ElapsedMilliseconds, message); }