Пример #1
0
 protected static void BuildTestChildren(IAssemblyInfo assembly, NUnitTest parentTest, NUnit.Core.ITest parentNUnitTest)
 {
     if (parentNUnitTest.Tests != null)
     {
         foreach (NUnit.Core.ITest childNUnitTest in parentNUnitTest.Tests)
         {
             BuildTest(assembly, parentTest, childNUnitTest);
         }
     }
 }
        public override void Finish()
        {
            var nunitNamespaceTreeBuilder = new NUnit.Core.NamespaceTreeBuilder(new NUnit.Core.TestSuite(assembly.Name));
            foreach (var nunitFixture in nunitFixtures)
                nunitNamespaceTreeBuilder.Add(nunitFixture);
            NUnit.Core.TestSuite nunitRootSuite = nunitNamespaceTreeBuilder.RootSuite;

            var assemblyTest = new NUnitTest(assembly.Name, assembly, nunitRootSuite);
            PopulateMetadata(assemblyTest);
            PopulateAssemblyTestMetadata(assemblyTest, assembly);
            testModel.RootTest.AddChild(assemblyTest);

            BuildTestChildren(assembly, assemblyTest, nunitRootSuite);
        }
Пример #3
0
            private void Initialize()
            {
                progressMonitor.Canceled += HandleCanceled;

                // Build a reverse mapping from NUnit tests.
                testCommandsByTestName = new Dictionary <TestName, ITestCommand>();
                foreach (ITestCommand testCommand in testCommands)
                {
                    NUnitTest test = (NUnitTest)testCommand.Test;
                    test.ProcessTestNames(delegate(NUnit.Core.TestName testName)
                    {
                        testCommandsByTestName[testName] = testCommand;
                    });
                }
                nUnitTestFilter = new NUnitTestFilter(testCommandsByTestName);

                testContextStack = new Stack <ITestContext>();
            }
        public override void Finish()
        {
            var nunitNamespaceTreeBuilder = new NUnit.Core.NamespaceTreeBuilder(new NUnit.Core.TestSuite(assembly.Name));

            foreach (var nunitFixture in nunitFixtures)
            {
                nunitNamespaceTreeBuilder.Add(nunitFixture);
            }
            NUnit.Core.TestSuite nunitRootSuite = nunitNamespaceTreeBuilder.RootSuite;

            var assemblyTest = new NUnitTest(assembly.Name, assembly, nunitRootSuite);

            PopulateMetadata(assemblyTest);
            PopulateAssemblyTestMetadata(assemblyTest, assembly);
            testModel.RootTest.AddChild(assemblyTest);

            BuildTestChildren(assembly, assemblyTest, nunitRootSuite);
        }
Пример #5
0
            private void HandleTestOrSuiteFinished(NUnit.Core.TestResult nunitResult)
            {
                if (testContextStack.Count == 0)
                {
                    return;
                }

                ITestContext testContext = testContextStack.Peek();
                NUnitTest    test        = (NUnitTest)testContext.TestStep.Test;

                if (test.Test.TestName != nunitResult.Test.TestName)
                {
                    return;
                }

                testContextStack.Pop();

                progressMonitor.Worked(1);

                string logStreamName = nunitResult.ResultState == ResultState.Success ? MarkupStreamNames.Warnings : MarkupStreamNames.Failures;

                MarkupDocumentWriter logWriter = testContext.LogWriter;

                if (nunitResult.Message != null)
                {
                    using (logWriter[logStreamName].BeginSection(Resources.NUnitTestController_ResultMessageSectionName))
                        logWriter[logStreamName].Write(nunitResult.Message);
                }
                if (nunitResult.StackTrace != null)
                {
                    using (logWriter[logStreamName].BeginSection(Resources.NUnitTestController_ResultStackTraceSectionName))
                        using (logWriter[logStreamName].BeginMarker(Marker.StackTrace))
                            logWriter[logStreamName].Write(nunitResult.StackTrace);
                }

                testContext.AddAssertCount(nunitResult.AssertCount);
                TestResult result = testContext.FinishStep(CreateOutcomeFromResult(nunitResult), null);

                if (testContextStack.Count == 0)
                {
                    topResult = result;
                }
            }
Пример #6
0
        private static void BuildTest(IAssemblyInfo assembly, Test parentTest, NUnit.Core.ITest nunitTest)
        {
            string           kind;
            ICodeElementInfo codeElement;

            switch (nunitTest.TestType)
            {
#if NUNIT248
            case @"Test Case":
#elif NUNIT253
            case @"NUnitTestMethod":
#elif NUNIT254TO10 || NUNITLATEST
            case @"TestMethod":
#else
#error "Unrecognized NUnit framework version."
#endif
                kind        = TestKinds.Test;
                codeElement = ParseTestCaseName(assembly, nunitTest.TestName.FullName);
                break;

#if NUNIT248
            case @"Test Fixture":
#elif NUNIT253
            case @"NUnitTestFixture":
#elif NUNIT254TO10 || NUNITLATEST
            case @"TestFixture":
#else
#error "Unrecognized NUnit framework version."
#endif
                kind        = TestKinds.Fixture;
                codeElement = ParseTestFixtureName(assembly, nunitTest.TestName.FullName);
                break;

#if NUNIT254TO10 || NUNITLATEST
            case @"ParameterizedTest":
                kind        = TestKinds.Suite;
                codeElement = ParseTestCaseName(assembly, nunitTest.TestName.FullName);
                break;

            case @"Namespace":
                kind        = TestKinds.Namespace;
                codeElement = parentTest.CodeElement;
                break;
#endif

            default:
                kind        = nunitTest.IsSuite ? TestKinds.Suite : TestKinds.Test;
                codeElement = parentTest.CodeElement;
                break;
            }

            // Build the test.
            NUnitTest test = new NUnitTest(nunitTest.TestName.Name, codeElement, nunitTest);
            test.Kind       = kind;
            test.IsTestCase = !nunitTest.IsSuite;

            PopulateMetadata(test);

            parentTest.AddChild(test);
            BuildTestChildren(assembly, test, nunitTest);
        }
Пример #7
0
        protected static void PopulateMetadata(NUnitTest test)
        {
            NUnit.Core.ITest nunitTest = test.Test;

            if (!String.IsNullOrEmpty(nunitTest.Description))
            {
                test.Metadata.Add(MetadataKeys.Description, nunitTest.Description);
            }

            if (!String.IsNullOrEmpty(nunitTest.IgnoreReason))
            {
                test.Metadata.Add(MetadataKeys.IgnoreReason, nunitTest.IgnoreReason);
            }

            if (nunitTest.Categories != null)
            {
                foreach (string category in nunitTest.Categories)
                {
                    if (!string.IsNullOrEmpty(category))
                    {
                        test.Metadata.Add(MetadataKeys.Category, category);
                    }
                }
            }

            if (nunitTest.Properties != null)
            {
                foreach (DictionaryEntry entry in nunitTest.Properties)
                {
                    if (entry.Key != null && entry.Value != null)
                    {
                        string keyString = entry.Key.ToString();
                        if (!keyString.StartsWith("_") && keyString.Length != 0)
                        {
                            ICollection values = entry.Value as ICollection;
                            if (values != null)
                            {
                                foreach (object value in values)
                                {
                                    if (value != null)
                                    {
                                        test.Metadata.Add(keyString, value.ToString());
                                    }
                                }
                            }
                            else
                            {
                                test.Metadata.Add(keyString, entry.Value.ToString());
                            }
                        }
                    }
                }
            }

            ICodeElementInfo codeElement = test.CodeElement;

            if (codeElement != null)
            {
                // Add documentation.
                string xmlDocumentation = codeElement.GetXmlDocumentation();
                if (xmlDocumentation != null)
                {
                    test.Metadata.Add(MetadataKeys.XmlDocumentation, xmlDocumentation);
                }
            }
        }
        private static void BuildTest(IAssemblyInfo assembly, Test parentTest, NUnit.Core.ITest nunitTest)
        {
            string kind;
            ICodeElementInfo codeElement;

            switch (nunitTest.TestType)
            {
#if NUNIT248
                case @"Test Case":
#elif NUNIT253
                case @"NUnitTestMethod":
#elif NUNIT254TO10 || NUNITLATEST
                case @"TestMethod":
#else
#error "Unrecognized NUnit framework version."
#endif
                    kind = TestKinds.Test;
                    codeElement = ParseTestCaseName(assembly, nunitTest.TestName.FullName);
                    break;

#if NUNIT248
                case @"Test Fixture":
#elif NUNIT253
                case @"NUnitTestFixture":
#elif NUNIT254TO10 || NUNITLATEST
                case @"TestFixture":
#else
#error "Unrecognized NUnit framework version."
#endif                    
                    kind = TestKinds.Fixture;
                    codeElement = ParseTestFixtureName(assembly, nunitTest.TestName.FullName);
                    break;

#if NUNIT254TO10 || NUNITLATEST
                case @"ParameterizedTest":
                    kind = TestKinds.Suite;
                    codeElement = ParseTestCaseName(assembly, nunitTest.TestName.FullName);
                    break;

                case @"Namespace":
                    kind = TestKinds.Namespace;
                    codeElement = parentTest.CodeElement;
                    break;
#endif

                default:
                    kind = nunitTest.IsSuite ? TestKinds.Suite : TestKinds.Test;
                    codeElement = parentTest.CodeElement;
                    break;
            }

            // Build the test.
            NUnitTest test = new NUnitTest(nunitTest.TestName.Name, codeElement, nunitTest);
            test.Kind = kind;
            test.IsTestCase = !nunitTest.IsSuite;

            PopulateMetadata(test);

            parentTest.AddChild(test);
            BuildTestChildren(assembly, test, nunitTest);
        }
        protected static void PopulateMetadata(NUnitTest test)
        {
            NUnit.Core.ITest nunitTest = test.Test;

            if (!String.IsNullOrEmpty(nunitTest.Description))
                test.Metadata.Add(MetadataKeys.Description, nunitTest.Description);

            if (!String.IsNullOrEmpty(nunitTest.IgnoreReason))
                test.Metadata.Add(MetadataKeys.IgnoreReason, nunitTest.IgnoreReason);

            if (nunitTest.Categories != null)
            {
                foreach (string category in nunitTest.Categories)
                    if (! string.IsNullOrEmpty(category))
                        test.Metadata.Add(MetadataKeys.Category, category);
            }

            if (nunitTest.Properties != null)
            {
                foreach (DictionaryEntry entry in nunitTest.Properties)
                {
                    if (entry.Key != null && entry.Value != null)
                    {
                        string keyString = entry.Key.ToString();
                        if (!keyString.StartsWith("_") && keyString.Length != 0)
                        {
                            ICollection values = entry.Value as ICollection;
                            if (values != null)
                            {
                                foreach (object value in values)
                                    if (value != null)
                                        test.Metadata.Add(keyString, value.ToString());
                            }
                            else
                            {
                                test.Metadata.Add(keyString, entry.Value.ToString());
                            }
                        }
                    }
                }
            }

            ICodeElementInfo codeElement = test.CodeElement;
            if (codeElement != null)
            {
                // Add documentation.
                string xmlDocumentation = codeElement.GetXmlDocumentation();
                if (xmlDocumentation != null)
                    test.Metadata.Add(MetadataKeys.XmlDocumentation, xmlDocumentation);
            }
        }
 protected static void BuildTestChildren(IAssemblyInfo assembly, NUnitTest parentTest, NUnit.Core.ITest parentNUnitTest)
 {
     if (parentNUnitTest.Tests != null)
     {
         foreach (NUnit.Core.ITest childNUnitTest in parentNUnitTest.Tests)
             BuildTest(assembly, parentTest, childNUnitTest);
     }
 }