Пример #1
0
        public void Visit(TestCase testCase)
        {
            Code.Require(testCase, "testCase");

            if (ShouldVisit(testCase))
            {
                VSTestCase test = GenerateTestCase(testCase);
                TestCaseUtils.AddTestCase(test, this.DiscoverySink);
            }
        }
Пример #2
0
        /// <summary>
        /// Visits the provided TestCase
        /// </summary>
        /// <param name="testCase">The TestCase which is to be visited</param>
        /// <param name="displayName">The test case display name to use (overrides the test case name)</param>
        private void Visit(TestCase testCase, string displayName)
        {
            Code.Require(testCase, "testCase");

            VSTestCase test = GenerateTestCase(testCase);

            test.DisplayName = string.IsNullOrEmpty(displayName) ? test.DisplayName : displayName;

            // Send to discovery sink
            Logger.Info("Found test: {0}", test.FullyQualifiedName);
            this.DiscoverySink.SendTestCase(test);
        }
Пример #3
0
        /// <summary>
        /// Generates a Visual Studio equivalent test case structure.
        /// </summary>
        /// <param name="testCase">The Boost.Test.TestCase to convert.</param>
        /// <returns>An equivalent Visual Studio TestCase structure to the one provided.</returns>

        private VSTestCase GenerateTestCase(TestCase testCase)
        {
            VSTestCase test = new VSTestCase(
                testCase.FullyQualifiedName,
                BoostTestExecutor.ExecutorUri,
                this.Source
                );

            test.DisplayName = testCase.Name;

            if (testCase.Source != null)
            {
                // NOTE As of Boost 1.61, this warning might be triggered when BOOST_DATA_TEST_CASEs are used due to irregular DOT output
                if (!Path.IsPathRooted(testCase.Source.File) && this.OutputLog)
                {
                    Logger.Info("Relative Paths are being used. Please note that test navigation from the Test Explorer window will not be available. To enable such functionality, the Use Full Paths setting under C++ -> Advanced in the project's Property Page must be set to Yes (/FC).");
                    this.OutputLog = false;
                }

                test.CodeFilePath = testCase.Source.File;
                test.LineNumber   = testCase.Source.LineNumber;
            }

            // Register the test suite as a trait
            test.Traits.Add(new Trait(VSTestModel.TestSuiteTrait, GetParentFullyQualifiedName(testCase)));

            // Register enabled and disabled as traits
            test.Traits.Add(new Trait(VSTestModel.StatusTrait, (testCase.DefaultEnabled ? VSTestModel.TestEnabled : VSTestModel.TestDisabled)));

            TestUnit unit = testCase;

            while (unit != null)
            {
                foreach (string label in unit.Labels)
                {
                    // Register each and every label as an individual trait
                    test.Traits.Add(new Trait(label, string.Empty));
                }

                // Test cases inherit the labels of parent test units
                // Reference: http://www.boost.org/doc/libs/1_60_0/libs/test/doc/html/boost_test/tests_organization/tests_grouping.html
                unit = unit.Parent;
            }

            // Record Boost version if available
            if (!string.IsNullOrEmpty(this.Version))
            {
                test.SetPropertyValue(VSTestModel.VersionProperty, this.Version);
            }

            return(test);
        }
        /// <summary>
        /// Asserts 'common' test case details between the Boost test case and the respective Visual Studio test case
        /// </summary>
        /// <param name="test">The Visual Studio TestCase instance to verify</param>
        /// <param name="expected">The Boost TestCase to which test should match to</param>
        /// <param name="source">The source from which the Boost Test case was discovered from</param>
        private static void AssertCommonTestCaseDetails(VSTestCase test, BoostTestCase expected, string source)
        {
            Assert.That(expected, Is.Not.Null);
            Assert.That(test, Is.Not.Null);

            Assert.That(test.Source, Is.EqualTo(source));
            Assert.That(test.ExecutorUri, Is.EqualTo(new Uri(BoostTestExecutor.ExecutorUriString)));
            Assert.That(test.FullyQualifiedName, Is.EqualTo(expected.FullyQualifiedName));

            if (expected.Source != null)
            {
                Assert.That(test.CodeFilePath, Is.EqualTo(expected.Source.File));
                Assert.That(test.LineNumber, Is.EqualTo(expected.Source.LineNumber));
            }
        }
Пример #5
0
        /// <summary>
        /// Provides the fully qualified name of the parent TestUnit of the provided TestCase
        /// </summary>
        /// <param name="test">The TestCase whose parent TestUnit is to be queried</param>
        /// <returns>The fully qualified name of the parent TestUnit</returns>
        private static string GetParentFullyQualifiedName(TestCase test)
        {
            Code.Require(test, "test");

            TestUnit parent = test.Parent;

            Debug.Assert(parent != null);

            // Since the master test suite name is not included in the fully qualified name, identify
            // this edge case and explicitly return the master test suite name in such cases.
            if (parent.Parent == null)
            {
                return(string.IsNullOrEmpty(parent.Name) ? QualifiedNameBuilder.DefaultMasterTestSuiteName : parent.Name);
            }

            return(parent.FullyQualifiedName);
        }
Пример #6
0
        /// <summary>
        /// Generates a Visual Studio equivalent test case structure.
        /// </summary>
        /// <param name="testCase">The Boost.Test.TestCase to convert.</param>
        /// <returns>An equivalent Visual Studio TestCase structure to the one provided.</returns>
        private VSTestCase GenerateTestCase(TestCase testCase)
        {
            VSTestCase test = new VSTestCase(
                GetFullyQualifiedName(testCase),
                BoostTestExecutor.ExecutorUri,
                this.Source
                );

            test.DisplayName = testCase.Name;

            if (testCase.Source != null)
            {
                test.CodeFilePath = testCase.Source.File;
                test.LineNumber   = testCase.Source.LineNumber;
            }

            // Register the test suite as a trait
            test.Traits.Add(new Trait(VSTestModel.TestSuiteTrait, GetParentFullyQualifiedName(testCase)));

            TestUnit unit = testCase;

            while (unit != null)
            {
                foreach (string label in unit.Labels)
                {
                    // Register each and every label as an individual trait
                    test.Traits.Add(new Trait(VSTestModel.LabelTrait, ('@' + label)));
                }

                // Test cases inherit the labels of parent test units
                // Reference: http://www.boost.org/doc/libs/1_60_0/libs/test/doc/html/boost_test/tests_organization/tests_grouping.html
                unit = unit.Parent;
            }

            return(test);
        }
            public void Visit(TestCase testCase)
            {
                Utility.Code.Require(testCase, "testCase");

                TestResult result = this.Collection[testCase];

                if ((result != null) && (this.ResultTypes.Contains(result.Result)))
                {
                    ++this.Count;
                }
            }
 /// <summary>
 /// Parses a TestCase node.
 /// </summary>
 /// <param name="node">The XPathNavigator pointing to a TestCase node.</param>
 /// <param name="parent">The parent TestSuite to which TestUnits are attached to.</param>
 /// <param name="collection">The TestResultCollection which will host the result.</param>
 private static void ParseTestCaseReport(XPathNavigator node, TestSuite parent, TestResultCollection collection)
 {
     TestCase testCase = new TestCase(node.GetAttribute(Xml.Name, string.Empty), parent);
     collection[testCase] = ParseTestResult(node, testCase, collection);
 }
        public void Visit(TestCase testCase)
        {
            Code.Require(testCase, "testCase");

            if (ShouldVisit(testCase))
            {
                VSTestCase test = GenerateTestCase(testCase);

                //send to discovery sink
                if (null != this.DiscoverySink)
                {
                    Logger.Info("Found test: {0}", test.FullyQualifiedName);
                    this.DiscoverySink.SendTestCase(test);
                }
            }
        }
        /// <summary>
        /// Builds a new TestCase.
        /// </summary>
        /// <param name="name">Test Case Name</param>
        /// <param name="id">Test Case Id</param>
        /// <param name="source">Test Case source file debug information</param>
        /// <param name="labels">Test Case labels</param>
        /// <returns>this</returns>
        public TestFrameworkBuilder TestCase(string name, int? id, SourceFileInfo source, IEnumerable<string> labels)
        {
            TestCase testCase = new TestCase(name, this.Parent);

            testCase.Id = id;
            testCase.Source = source;
            testCase.Labels = labels;

            return this;
        }
        /// <summary>
        /// Builds a new TestCase.
        /// </summary>
        /// <param name="name">Test Case Name</param>
        /// <param name="id">Test Case Id</param>
        /// <param name="source">Test Case source file debug information</param>
        /// <param name="labels">Test Case labels</param>
        /// <param name="enabled">Test Case enabled or disabled</param>
        /// <returns>this</returns>
        public TestFrameworkBuilder TestCase(string name, int? id, SourceFileInfo source, IEnumerable<string> labels, bool enabled)
        {
            TestCase testCase = new TestCase(name, this.Parent);

            testCase.Id = id;
            testCase.Source = source;
            testCase.Labels = ((labels == null)? Enumerable.Empty<string>() : labels);
            testCase.DefaultEnabled = enabled;

            return this;
        }
            public void Visit(TestCase testCase)
            {
                Code.Require(testCase, "testCase");

                // Convert from Boost.Test.TestCase to a Visual Studio TestCase object
                VSTestCase test = GenerateTestCase(testCase);

                if (test != null)
                {
                    Logger.Info("Found test: {0}", testCase.FullyQualifiedName);

                    ++Count;

                    // Register test case
                    Sink.SendTestCase(test);
                }
            }
Пример #13
0
 /// <summary>
 /// Provides the fully qualified name of the provided TestCase
 /// </summary>
 /// <param name="test">The test case whose fully qualified is to be acquired</param>
 /// <returns>The fully qualified name of the provided TestCase</returns>
 private static string GetFullyQualifiedName(TestCase test)
 {
     Code.Require(test, "test");
     return(test.FullyQualifiedName);
 }
Пример #14
0
 /// <summary>
 /// States whether the provided test case should be visited
 /// </summary>
 /// <param name="unit">The test case under consideration</param>
 /// <returns>true if the provided TestCase should be visited; false otherwise</returns>
 protected virtual bool ShouldVisit(TestCase test)
 {
     return(true);
 }
        /// <summary>
        /// Parses a TestCase node.
        /// </summary>
        /// <param name="node">The XPathNavigator pointing to a TestCase node.</param>
        /// <param name="parent">The parent TestSuite to which TestUnits are attached to.</param>
        /// <param name="collection">The TestResultCollection which will host the result.</param>
        private static void ParseTestCaseReport(XPathNavigator node, TestSuite parent, TestResultCollection collection)
        {
            QualifiedNameBuilder fullname = new QualifiedNameBuilder(parent);
            fullname.Push(node.GetAttribute(Xml.Name, string.Empty));

            TestCase testCase = null;

            // If the test is already available, reuse it
            TestResult current = collection[fullname.ToString()];
            if (current != null)
            {
                testCase = current.Unit as TestCase;
            }

            // Else construct and add it to the appropriate parent
            if (testCase == null)
            {
                testCase = new TestCase(fullname.Peek(), parent);
            }

            TestResult result = ParseTestResult(node, testCase, collection);

            // Aggregate results. Common use-case in BOOST_DATA_TEST_CASE.
            collection[fullname.ToString()] = Aggregate(result, current);
        }
        /// <summary>
        /// Builds a new TestCase.
        /// </summary>
        /// <param name="name">Test Case Name</param>
        /// <param name="id">Test Case Id</param>
        /// <param name="source">Test Case source file debug information</param>
        /// <returns>this</returns>
        public TestFrameworkBuilder TestCase(string name, int? id, SourceFileInfo source)
        {
            TestCase testCase = new TestCase(name, this.Parent);
            testCase.Id = id;
            testCase.Source = source;

            return this;
        }
 public void Visit(TestCase testCase)
 {
     this.CaseSerializer.Serialize(this.Writer, testCase);
 }
 /// <summary>
 /// States whether the provided test case should be visited
 /// </summary>
 /// <param name="unit">The test case under consideration</param>
 /// <returns>true if the provided TestCase should be visited; false otherwise</returns>
 protected virtual bool ShouldVisit(TestCase test)
 {
     return true;
 }
Пример #19
0
        public void Visit(TestCase testCase)
        {
            Code.Require(testCase, "testCase");

            Visit(testCase, testCase.Name);
        }
 /// <summary>
 /// Provides the fully qualified name of the provided TestCase
 /// </summary>
 /// <param name="test">The test case whose fully qualified is to be acquired</param>
 /// <returns>The fully qualified name of the provided TestCase</returns>
 private static string GetFullyQualifiedName(TestCase test)
 {
     Code.Require(test, "test");
     return test.FullyQualifiedName;
 }
            /// <summary>
            /// Generates a Visual Studio equivalent test case structure.
            /// </summary>
            /// <param name="testCase">The Boost.Test.TestCase to convert.</param>
            /// <returns>An equivalent Visual Studio TestCase structure to the one provided.</returns>
            private VSTestCase GenerateTestCase(TestCase testCase)
            {
                // Temporarily push TestCase on TestSuite name builder to acquire the fully qualified name of the TestCase
                this.TestSuite.Push(testCase);

                VSTestCase test = new VSTestCase(
                    this.TestSuite.ToString(),
                    BoostTestExecutor.ExecutorUri,
                    this.Source
                );

                // Reset TestSuite QualifiedNameBuilder to original value
                this.TestSuite.Pop();

                if (testCase.Source != null)
                {
                    test.CodeFilePath = testCase.Source.File;
                    test.LineNumber = testCase.Source.LineNumber;
                }

                test.DisplayName = testCase.Name;

                // Register the test suite as a trait
                test.Traits.Add(new Trait(VSTestModel.TestSuiteTrait, GetCurrentTestSuite()));

                return test;
            }
        /// <summary>
        /// Provides the fully qualified name of the parent TestUnit of the provided TestCase
        /// </summary>
        /// <param name="test">The TestCase whose parent TestUnit is to be queried</param>
        /// <returns>The fully qualified name of the parent TestUnit</returns>
        private static string GetParentFullyQualifiedName(TestCase test)
        {
            Code.Require(test, "test");

            TestUnit parent = test.Parent;
            Debug.Assert(parent != null);

            // Since the master test suite name is not included in the fully qualified name, identify
            // this edge case and explicitly return the master test suite name in such cases.
            if (parent.Parent == null)
            {
                return string.IsNullOrEmpty(parent.Name) ? QualifiedNameBuilder.DefaultMasterTestSuiteName : parent.Name;
            }

            return parent.FullyQualifiedName;
        }
 protected override bool ShouldVisit(TestCase test)
 {
     return true;
 }
        /// <summary>
        /// Generates a Visual Studio equivalent test case structure.
        /// </summary>
        /// <param name="testCase">The Boost.Test.TestCase to convert.</param>
        /// <returns>An equivalent Visual Studio TestCase structure to the one provided.</returns>
        private VSTestCase GenerateTestCase(TestCase testCase)
        {
            VSTestCase test = new VSTestCase(
                GetFullyQualifiedName(testCase),
                BoostTestExecutor.ExecutorUri,
                this.Source
            );

            test.DisplayName = testCase.Name;

            if (testCase.Source != null)
            {
                // NOTE As of Boost 1.61, this warning might be triggered when BOOST_DATA_TEST_CASEs are used due to irregular DOT output
                if (!Path.IsPathRooted(testCase.Source.File) && this.OutputLog)
                {
                    Logger.Info("Relative Paths are being used. Please note that test navigation from the Test Explorer window will not be available. To enable such functionality, the Use Full Paths setting under C++ -> Advanced in the project's Property Page must be set to Yes (/FC).");
                    this.OutputLog = false;
                }

                test.CodeFilePath = testCase.Source.File;
                test.LineNumber = testCase.Source.LineNumber;
            }

            // Register the test suite as a trait
            test.Traits.Add(new Trait(VSTestModel.TestSuiteTrait, GetParentFullyQualifiedName(testCase)));

            // Register enabled and disabled as traits
            test.Traits.Add(new Trait(VSTestModel.StatusTrait, (testCase.DefaultEnabled ? VSTestModel.TestEnabled : VSTestModel.TestDisabled)));

            TestUnit unit = testCase;
            while (unit != null)
            {
                foreach (string label in unit.Labels)
                {
                    // Register each and every label as an individual trait
                    test.Traits.Add(new Trait(label, ""));
                }

                // Test cases inherit the labels of parent test units
                // Reference: http://www.boost.org/doc/libs/1_60_0/libs/test/doc/html/boost_test/tests_organization/tests_grouping.html
                unit = unit.Parent;
            }

            return test;
        }