コード例 #1
0
 private void Run(string path, TestNamespace ns, TestCaseFilter filter, TestReporter reporter)
 {
     reporter.BeginSuite(ns);
     foreach (var item in GetItemOrder(ns.Items))
     {
         string itemPath = path;
         if (itemPath != "")
         {
             itemPath += '.';
         }
         itemPath += item.Name;
         if (filter.Match(itemPath))
         {
             if (item is TestNamespace)
             {
                 Run(itemPath, item as TestNamespace, filter, reporter);
             }
             if (item is TestFixtureClass)
             {
                 Run(itemPath, item as TestFixtureClass, filter, reporter);
             }
         }
     }
     reporter.EndSuite(ns, 0);
 }
コード例 #2
0
        private void Run(string path, TestFixtureClass fixtureClass, TestCaseFilter filter, TestReporter reporter)
        {
            reporter.BeginSuite(fixtureClass);
            if (fixtureClass.HasIgnoreAttribute)
            {
                reporter.Ignore(fixtureClass.IgnoreMessage);
                reporter.EndSuite(fixtureClass, 0);
                return;
            }

            TestFixture fixture   = null;
            bool        setupDone = false;

            try
            {
                fixture = fixtureClass.CreateInstance();
                fixture.TestFixtureSetUp();
                setupDone = true;
            }
            catch (System.Exception e)
            {
                Exception.Report(e, reporter);
            }

            foreach (var test in GetItemOrder(fixtureClass.Tests))
            {
                var testPath = path + '.' + test.Name;
                if (filter.Match(testPath))
                {
                    Run(setupDone, testPath, fixture, test, filter, reporter);
                }
            }

            if (setupDone)
            {
                TestFixtureTearDown(fixture, reporter);
            }

            reporter.EndSuite(fixtureClass, 0);
        }
コード例 #3
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);
        }