public UUnitTestSuite(string classname) { _testResults = new UUnitTestResults(classname); }
public void Run(UUnitTestResults testResults) { TestFinishState testFinishState = TestFinishState.FAILED; string message = null, stacktrace = null; eachTestStopwatch.Reset(); setUpStopwatch.Reset(); tearDownStopwatch.Reset(); try { testResults.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 testFinishState = TestFinishState.PASSED; } catch (UUnitAssertException e) { message = e.message; stacktrace = e.StackTrace; testFinishState = TestFinishState.FAILED; } catch (UUnitSkipException) { // message remains null testFinishState = TestFinishState.SKIPPED; } catch (TargetInvocationException e) { message = e.InnerException.Message; stacktrace = e.InnerException.StackTrace; testFinishState = TestFinishState.FAILED; } catch (Exception e) { message = e.Message; stacktrace = e.StackTrace; testFinishState = TestFinishState.FAILED; } finally { eachTestStopwatch.Stop(); if (testFinishState != TestFinishState.SKIPPED) { try { tearDownStopwatch.Start(); TearDown(); tearDownStopwatch.Stop(); } catch (Exception e) { message = e.Message; stacktrace = e.StackTrace; testFinishState = TestFinishState.FAILED; } } } testResults.TestComplete(testMethodName, testFinishState, eachTestStopwatch.ElapsedMilliseconds, message, stacktrace); }