예제 #1
0
 public void EndTest(TestItem test, int ms, TestCaseState state)
 {
     if (logLevel == LogLevel.All)
     {
         System.Console.WriteLine("Leaving test case {0}", test.Name);
     }
     System.Console.WriteLine("#TestFinished {0} {1} {2}", test.Id, ms, TestCaseStateToString(state));
 }
예제 #2
0
        private static string TestCaseStateToString(TestCaseState state)
        {
            switch (state)
            {
            case TestCaseState.Ignored: return("-");

            case TestCaseState.Failed: return("0");

            case TestCaseState.Success: return("1");
            }
            return("");
        }
예제 #3
0
        private void Run(bool ok, TestFixture fixture, Test test, TestCase testCase, TestReporter reporter)
        {
            reporter.BeginTest(testCase);
            if (!ok)
            {
                reporter.EndTest(testCase, 0, TestCaseState.Failed);
                return;
            }

            bool          setUpDone = false;
            TestCaseState runState  = TestCaseState.Failed;

            try
            {
                fixture.SetUp();
                setUpDone = true;
                testCase.Run(fixture, reporter);
                runState = TestCaseState.Success;
            }
            catch (System.Exception e)
            {
                Exception.Report(e, reporter);
            }

            TestCaseState state = TestCaseState.Failed;

            if (setUpDone)
            {
                try
                {
                    fixture.TearDown();
                    state = runState;
                }
                catch (System.Exception e)
                {
                    Exception.Report(e, reporter);
                }
            }
            reporter.EndTest(testCase, 0, state);
        }
예제 #4
0
        private void Run(bool ok, string path, TestFixture fixture, Test test, TestCaseFilter filter, TestReporter reporter)
        {
            if (test.TestCases.Count > 0)
            {
                reporter.BeginSuite(test);
                foreach (var testCase in GetItemOrder(test.TestCases))
                {
                    if (filter.Match(path + "." + testCase.Name))
                    {
                        Run(ok, fixture, test, testCase, reporter);
                    }
                }
                reporter.EndSuite(test, 0);
                return;
            }

            reporter.BeginTest(test);
            if (!ok)
            {
                reporter.EndTest(test, 0, TestCaseState.Failed);
                return;
            }
            if (test.HasIgnoreAttribute)
            {
                reporter.Ignore(test.IgnoreMessage);
                reporter.EndTest(test, 0, TestCaseState.Ignored);
                return;
            }

            bool          setUpDone = false;
            TestCaseState runState  = TestCaseState.Failed;

            try
            {
                fixture.SetUp();
                setUpDone = true;
                test.Run(fixture, reporter);
                runState = TestCaseState.Success;
            }
            catch (System.Exception e)
            {
                if (Exception.IsExpected(e, typeof(NUnit.Framework.IgnoreException).FullName))
                {
                    runState = TestCaseState.Ignored;
                    reporter.Ignore(Exception.GetMessage(e));
                }
                else
                {
                    Exception.Report(e, reporter);
                }
            }

            TestCaseState state = TestCaseState.Failed;

            if (setUpDone)
            {
                try
                {
                    fixture.TearDown();
                    state = runState;
                }
                catch (System.Exception e)
                {
                    Exception.Report(e, reporter);
                }
            }
            reporter.EndTest(test, 0, state);
        }