コード例 #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
 static private void TestFixtureTearDown(TestFixture fixture, TestReporter reporter)
 {
     try
     {
         fixture.TestFixtureTearDown();
     }
     catch (System.Exception e)
     {
         Exception.Report(e, reporter);
     }
 }
コード例 #3
0
ファイル: Test.cs プロジェクト: fcccode/BoostTestUi
        public void Run(TestFixture fixture, TestReporter reporter)
        {
            var    exception             = Reflection.GetAttribute(methodInfo, typeof(NUnit.Framework.ExpectedExceptionAttribute), false);
            string expectedExceptionName = null;

            if (exception != null)
            {
                expectedExceptionName = (string)Reflection.GetProperty(exception, "ExpectedExceptionName");
                if (expectedExceptionName == null)
                {
                    expectedExceptionName = "";
                }
            }

            int repeatCount     = 1;
            var repeatAttribute = Reflection.GetAttribute(methodInfo, typeof(NUnit.Framework.RepeatAttribute), false);
            var propertiesValue = Reflection.GetProperty(repeatAttribute, "Properties");

            if (propertiesValue != null)
            {
                var properties = (System.Collections.IDictionary)propertiesValue;
                repeatCount = (int)properties["Repeat"];
            }

            try
            {
                for (int i = 0; i < repeatCount; ++i)
                {
                    fixture.Invoke(methodInfo);
                }
            }
            catch (System.Exception e)
            {
                if (Exception.IsSuccessException(e))
                {
                    reporter.Pass((string)Reflection.GetProperty(Exception.InnerException(e), "Message"));
                }
                else
                {
                    Exception.Handle(e, expectedExceptionName);
                    return;
                }
            }

            if (expectedExceptionName != null)
            {
                throw new NUnit.Framework.NoExpectedException("expected " + expectedExceptionName);
            }
        }
コード例 #4
0
 public void Run(TestFixture fixture, TestReporter reporter)
 {
     try
     {
         fixture.Invoke(methodInfo, arguments);
     }
     catch (System.Exception e)
     {
         if (Exception.IsSuccessException(e))
         {
             reporter.Pass((string)Reflection.GetProperty(Exception.InnerException(e), "Message"));
         }
         else
         {
             throw;
         }
     }
 }
コード例 #5
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);
        }
コード例 #6
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);
        }
コード例 #7
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);
        }
コード例 #8
0
 public void Run(TestCaseFilter filter, TestReporter reporter)
 {
     reporter.BeginRun();
     Run("", global, filter, reporter);
     reporter.EndRun();
 }