Exemplo n.º 1
0
        public void TestComplete(string testName, TestFinishState finishState, long stopwatchMs, string message, string stacktrace)
        {
            TestCaseReport report = new TestCaseReport
            {
                message     = message,
                classname   = InternalReport.name,
                failureText = finishState.ToString(),
                finishState = finishState,
                name        = testName,
                time        = TimeSpan.FromMilliseconds(stopwatchMs)
            };

            if (InternalReport.testResults == null)
            {
                InternalReport.testResults = new List <TestCaseReport>();
            }
            InternalReport.testResults.Add(report);

            switch (finishState)
            {
            case (TestFinishState.PASSED):
                InternalReport.passed += 1; break;

            case (TestFinishState.FAILED):
                InternalReport.failures += 1; break;

            case (TestFinishState.SKIPPED):
                InternalReport.skipped += 1; break;
            }

            // TODO: Add hooks for SuiteSetUp and SuiteTearDown, so this can be estimated more accurately
            InternalReport.time = DateTime.UtcNow - InternalReport.timestamp; // For now, update the duration on every test complete - the last one will be essentially correct
        }
Exemplo n.º 2
0
        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);
        }