/// <summary>
        /// Asserts test details for tests contained within the "BoostUnitTestSample.cpp" source file
        /// </summary>
        /// <param name="tests">The discovered test case enumeration</param>
        /// <param name="source">The source for which "BoostUnitTestSample.cpp" was compiled to</param>
        /// <param name="codeFilePath">The fully qualified path for the on-disk version of "BoostUnitTestSample.cpp"</param>
        private void AssertBoostUnitTestSampleTestDetails(IEnumerable <VSTestCase> tests, string source, string codeFilePath)
        {
            VSTestCase test123 = AssertTestDetails(tests, QualifiedNameBuilder.FromString("Suite1/BoostUnitTest123"), source);

            AssertSourceDetails(test123, codeFilePath, 16);

            VSTestCase test1234 = AssertTestDetails(tests, QualifiedNameBuilder.FromString("Suite1/BoostUnitTest1234"), source);

            AssertSourceDetails(test1234, codeFilePath, 20);

            VSTestCase test12345 = AssertTestDetails(tests, QualifiedNameBuilder.FromString("BoostUnitTest12345"), source);

            AssertSourceDetails(test12345, codeFilePath, 26);

            VSTestCase testint = AssertTestDetails(tests, QualifiedNameBuilder.FromString("my_test<int>"), source);

            AssertSourceDetails(testint, codeFilePath, 33);

            VSTestCase testlong = AssertTestDetails(tests, QualifiedNameBuilder.FromString("my_test<long>"), source);

            AssertSourceDetails(testlong, codeFilePath, 33);

            VSTestCase testchar = AssertTestDetails(tests, QualifiedNameBuilder.FromString("my_test<char>"), source);

            AssertSourceDetails(testchar, codeFilePath, 33);
        }
        private void AssertBoostUnitTestSampleRequiringUseOfFilters(IEnumerable <VSTestCase> tests, string source,
                                                                    string codeFilePath)
        {
            VSTestCase test1 = AssertTestDetails(tests, QualifiedNameBuilder.FromString("Suite1/BoostUnitTest123"), source);

            AssertSourceDetails(test1, codeFilePath, 16);

            VSTestCase test2 = AssertTestDetails(tests, QualifiedNameBuilder.FromString("Suite1/BoostUnitTest1234"), source);

            AssertSourceDetails(test2, codeFilePath, 20);

            VSTestCase test3 = AssertTestDetails(tests, QualifiedNameBuilder.FromString("BoostUnitTest12345"), source);

            AssertSourceDetails(test3, codeFilePath, 26);

            VSTestCase testint = AssertTestDetails(tests, QualifiedNameBuilder.FromString("my_test<int>"), source);

            AssertSourceDetails(testint, codeFilePath, 40);

            VSTestCase testlong = AssertTestDetails(tests, QualifiedNameBuilder.FromString("my_test<long>"), source);

            AssertSourceDetails(testlong, codeFilePath, 40);

            VSTestCase testchar = AssertTestDetails(tests, QualifiedNameBuilder.FromString("my_test<char>"), source);

            AssertSourceDetails(testchar, codeFilePath, 40);

            VSTestCase testConditional = AssertTestDetails(tests, QualifiedNameBuilder.FromString("BoostUnitTestConditional"), source);

            AssertSourceDetails(testConditional, codeFilePath, 54);

            VSTestCase testMultiline = AssertTestDetails(tests, QualifiedNameBuilder.FromString("some_test"), source);

            AssertSourceDetails(testMultiline, codeFilePath, 72);
        }
        /// <summary>
        /// Asserts test details for tests contained within the "BoostFixtureTestSuite.cpp" source file
        /// </summary>
        /// <param name="tests">The discovered test case enumeration</param>
        /// <param name="source">The source for which "BoostFixtureTestSuite.cpp" was compiled to</param>
        /// <param name="codeFilePath">The fully qualified path for the on-disk version of "BoostFixtureTestSuite.cpp"</param>
        private void AssertBoostFixtureTestSuiteTestDetails(IEnumerable <VSTestCase> tests, string source, string codeFilePath)
        {
            VSTestCase test1 = AssertTestDetails(tests, QualifiedNameBuilder.FromString("FixtureSuite1/BoostTest1"), source);

            AssertSourceDetails(test1, codeFilePath, 30);

            VSTestCase test2 = AssertTestDetails(tests, QualifiedNameBuilder.FromString("FixtureSuite1/BoostTest2"), source);

            AssertSourceDetails(test2, codeFilePath, 35);

            VSTestCase test3 = AssertTestDetails(tests, QualifiedNameBuilder.FromString("BoostTest3"), source);

            AssertSourceDetails(test3, codeFilePath, 43);

            VSTestCase test4 = AssertTestDetails(tests, QualifiedNameBuilder.FromString("FixtureSuite2/Fixturetest_case1"), source);

            AssertSourceDetails(test4, codeFilePath, 50);

            VSTestCase testint = AssertTestDetails(tests, QualifiedNameBuilder.FromString("FixtureSuite2/TemplatedTest<int>"), source);

            AssertSourceDetails(testint, codeFilePath, 57);

            VSTestCase testlong = AssertTestDetails(tests, QualifiedNameBuilder.FromString("FixtureSuite2/TemplatedTest<long>"), source);

            AssertSourceDetails(testlong, codeFilePath, 57);

            VSTestCase testchar = AssertTestDetails(tests, QualifiedNameBuilder.FromString("FixtureSuite2/TemplatedTest<char>"), source);

            AssertSourceDetails(testchar, codeFilePath, 57);
        }
Example #4
0
        public void OneShotBatchTestStrategyForOldBoost()
        {
            var strategy = new OneShotTestBatchStrategy(RunnerFactory, Settings, ArgsBuilder);

            var template = new VSTestCase("test", BoostTestExecutor.ExecutorUri, "source");

            template.SetPropertyValue(VSTestModel.VersionProperty, null);
            template.Traits.Add(VSTestModel.TestSuiteTrait, "Master Test Suite");

            var template2 = new VSTestCase("test", BoostTestExecutor.ExecutorUri, "source");

            template2.SetPropertyValue(VSTestModel.VersionProperty, null);
            template2.Traits.Add(VSTestModel.TestSuiteTrait, "suite");

            var tests = GenerateDummyTests(template, 2).Concat(GenerateDummyTests(template2, 2)).ToList();
            var batch = strategy.BatchTests(tests).ToList();

            // 2 test runs, 1 for "Master Test Suite" and 1 for "suite"
            Assert.That(batch.Count, Is.EqualTo(2));

            foreach (var run in batch)
            {
                // The --run_test argument is to be used instead of the "BOOST_TEST_RUN_FILTERS" environment variable
                Assert.That(run.Arguments.Tests, Is.Not.Empty);
                Assert.That(run.Arguments.Environment.ContainsKey("BOOST_TEST_RUN_FILTERS"), Is.False);
            }
        }
Example #5
0
        public static VsTestCase CreateVsTestCase(string source,
                                                  TestCaseDescriptor descriptor)
        {
            try
            {
                var fqTestMethodName = $"{descriptor.ClassName}.{descriptor.MethodName}";
                var result           = new VsTestCase(fqTestMethodName, uri, source)
                {
                    DisplayName = Escape(descriptor.DisplayName)
                };

                result.Id           = GuidFromString(uri + descriptor.UniqueID);
                result.CodeFilePath = descriptor.SourceFileName;
                result.LineNumber   = descriptor.SourceLineNumber.GetValueOrDefault();

                //if (addTraitThunk != null)
                //{
                //    var traits = descriptor.Traits;

                //    foreach (var key in traits.Keys)
                //        foreach (var value in traits[key])
                //            addTraitThunk(result, key, value);
                //}

                return(result);
            }
#pragma warning disable CA1031, IDE0059, CS0168 // Do not catch general exception types, Unnecessary assignment of a value, Variable is declared but never used
            catch (Exception ex)
#pragma warning restore CA1031, IDE0059, CS0168 // Do not catch general exception types, Unnecessary assignment of a value, Variable is declared but never used
            {
                //logger.LogErrorWithSource(source, "Error creating Visual Studio test case for {0}: {1}", descriptor.DisplayName, ex);
                return(null);
            }
        }
Example #6
0
        public static TestCase ToTestCase(this VsTestCase vsTestCase)
        {
            var testCase = new TestCase(vsTestCase.FullyQualifiedName, vsTestCase.Source,
                                        vsTestCase.DisplayName, vsTestCase.CodeFilePath, vsTestCase.LineNumber);

            testCase.Traits.AddRange(vsTestCase.Traits.Select(ToTrait));
            return(testCase);
        }
        /// <summary>
        /// Asserts general test details for the test with the requested fully qualified name
        /// </summary>
        /// <param name="tests">The discovered test case enumeration</param>
        /// <param name="fqn">The fully qualified name of the test case to test</param>
        /// <param name="source">The expected test case source</param>
        /// <returns>The test case which has been tested</returns>
        private VSTestCase AssertTestDetails(IEnumerable <VSTestCase> tests, QualifiedNameBuilder fqn, string source)
        {
            VSTestCase vsTest = tests.FirstOrDefault(test => test.FullyQualifiedName == fqn.ToString());

            Assert.That(vsTest, Is.Not.Null);
            AssertTestDetails(vsTest, fqn, source);

            return(vsTest);
        }
        /// <summary>
        /// Asserts 'common' test case details between the test case encoded in the framework and the respective Visual Studio test case
        /// </summary>
        /// <param name="test">The Visual Studio TestCase instance to verify</param>
        /// <param name="framework">The framework to locate the test case from</param>
        /// <param name="fullyQualifiedName">The test case fully qualified name to locate</param>
        private static void AssertCommonTestCaseDetails(VSTestCase test, TestFramework framework, string fullyQualifiedName)
        {
            Assert.That(framework, Is.Not.Null);

            var expected = LocateTestCase(framework, fullyQualifiedName);

            Assert.That(expected, Is.Not.Null);

            AssertCommonTestCaseDetails(test, expected, framework.Source);
        }
 public static VsTestCase ToVsTestCase(this TestCase testCase)
 {
     var vsTestCase = new VsTestCase(testCase.FullyQualifiedName, TestExecutor.ExecutorUri, testCase.Source)
     {
         DisplayName = testCase.DisplayName,
         CodeFilePath = testCase.CodeFilePath,
         LineNumber = testCase.LineNumber
     };
     vsTestCase.Traits.AddRange(testCase.Traits.Select(ToVsTrait));
     return vsTestCase;
 }
Example #10
0
        public static VsTestCase ToVsTestCase(this TestCase testCase)
        {
            var vsTestCase = new VsTestCase(testCase.FullyQualifiedName, TestExecutor.ExecutorUri, testCase.Source)
            {
                DisplayName  = testCase.DisplayName,
                CodeFilePath = testCase.CodeFilePath,
                LineNumber   = testCase.LineNumber
            };

            vsTestCase.Traits.AddRange(testCase.Traits.Select(ToVsTrait));
            return(vsTestCase);
        }
        /// <summary>
        /// Asserts source file details for the provided test case
        /// </summary>
        /// <param name="vsTest">The test case to test</param>
        /// <param name="codeFilePath">The expected source file qualified path</param>
        /// <param name="lineNumber">The expected line number for the test case</param>
        private void AssertSourceDetails(VSTestCase vsTest, string codeFilePath, int lineNumber)
        {
            if (vsTest.CodeFilePath != null)
            {
                Assert.That(vsTest.CodeFilePath, Is.EqualTo(codeFilePath));
            }

            if (lineNumber != -1)
            {
                Assert.That(vsTest.LineNumber, Is.EqualTo(lineNumber));
            }
        }
        /// <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));
            }
        }
        /// <summary>
        /// Asserts general test details for the provided test case
        /// </summary>
        /// <param name="vsTest">The test case to test</param>
        /// <param name="fqn">The expected test case fully qualified name</param>
        /// <param name="source">The expected test case source</param>
        private void AssertTestDetails(VSTestCase vsTest, QualifiedNameBuilder fqn, string source)
        {
            Assert.That(vsTest, Is.Not.Null);
            Assert.That(vsTest.DisplayName, Is.EqualTo(fqn.Peek()));
            Assert.That(vsTest.ExecutorUri, Is.EqualTo(BoostTestExecutor.ExecutorUri));
            Assert.That(vsTest.Source, Is.EqualTo(source));

            string suite = fqn.Pop().ToString();

            if (string.IsNullOrEmpty(suite))
            {
                suite = QualifiedNameBuilder.DefaultMasterTestSuiteName;
            }

            Assert.That(vsTest.Traits.Where((trait) => (trait.Name == VSTestModel.TestSuiteTrait) && (trait.Value == suite)).Count(), Is.EqualTo(1));
        }
        public static TestCase ToTestCase(this VsTestCase vsTestCase)
        {
            var testCase = new TestCase(vsTestCase.FullyQualifiedName, vsTestCase.Source,
                                        vsTestCase.DisplayName, vsTestCase.CodeFilePath, vsTestCase.LineNumber);

            testCase.Traits.AddRange(vsTestCase.Traits.Select(ToTrait));

            var metaDataSerialization = vsTestCase.GetPropertyValue(TestMetaDataProperty);

            if (metaDataSerialization != null)
            {
                testCase.Properties.Add(new TestCaseMetaDataProperty((string)metaDataSerialization));
            }

            return(testCase);
        }
        public void DiscoverTestsUsingRunSettings()
        {
            using (DummySolution solution = new DummySolution(Source, new string[] { BoostUnitTestSampleRequiringUseOfFilters }))
            {
                DefaultTestContext context = new DefaultTestContext();
                context.RegisterSettingProvider(BoostTestAdapterSettings.XmlRootName, new BoostTestAdapterSettingsProvider());
                context.LoadEmbeddedSettings("BoostTestAdapterNunit.Resources.Settings.conditionalIncludesDisabled.runsettings");

                IEnumerable <VSTestCase> vsTests = Discover(solution, context);

                Assert.That(vsTests.Count(), Is.EqualTo(9));
                AssertBoostUnitTestSampleRequiringUseOfFilters(vsTests, solution);

                VSTestCase testConditional = AssertTestDetails(vsTests, QualifiedNameBuilder.FromString("BoostUnitTestShouldNotAppear3"), Source);
                AssertSourceDetails(testConditional, solution.SourceFileResourcePaths.First().Path, 47);
            }
        }
Example #16
0
        /// <summary>
        /// Given a VSTestCase as a template, generates up to count test instances
        /// based on the provided template with a unique name for each
        /// </summary>
        /// <param name="template">The template test case instance to base the generated instances upon</param>
        /// <param name="count">The total number of dummy test cases to generate</param>
        /// <returns>A collection of dummy test cases based on the provided template</returns>
        private IEnumerable <VSTestCase> GenerateDummyTests(VSTestCase template, int count)
        {
            for (int i = 0; i < count; ++i)
            {
                var test = new VSTestCase(template.FullyQualifiedName, template.ExecutorUri, template.Source);

                foreach (var property in template.Properties)
                {
                    test.SetPropertyValue(property, template.GetPropertyValue(property));
                }

                // Add a suffix to allow tests to be distinguishable
                test.FullyQualifiedName += '_' + i.ToString();

                yield return(test);
            }
        }
        /// <summary>
        /// Extracts the Boost version from the provided test case
        /// </summary>
        /// <param name="test">The test case to extract the version from</param>
        /// <returns>The version advertised by the provided test case or the zero version if the version is not available</returns>
        private static Version GetVersion(VSTestCase test)
        {
            // Use the Zero version as a dummy to identify a missing Boost Version property
            Version result = _zero;

            if (test != null)
            {
                string value = (string)test.GetPropertyValue(VSTestModel.VersionProperty);

                if (string.IsNullOrEmpty(value) || !Version.TryParse(value, out result))
                {
                    result = _zero;
                }
            }

            return(result);
        }
        /// <summary>
        /// Asserts test details for tests contained within the "BoostFixtureTestCase.cpp" source file
        /// </summary>
        /// <param name="tests">The discovered test case enumeration</param>
        /// <param name="source">The source for which "BoostFixtureTestCase.cpp" was compiled to</param>
        /// <param name="codeFilePath">The fully qualified path for the on-disk version of "BoostFixtureTestCase.cpp"</param>
        private void AssertBoostFixtureTestCaseTestDetails(IEnumerable <VSTestCase> tests, string source, string codeFilePath)
        {
            VSTestCase test1 = AssertTestDetails(tests, QualifiedNameBuilder.FromString("Suit1/BoostUnitTest1"), source);

            AssertSourceDetails(test1, codeFilePath, 19);

            VSTestCase test2 = AssertTestDetails(tests, QualifiedNameBuilder.FromString("Suit1/Fixturetest_case1"), source);

            AssertSourceDetails(test2, codeFilePath, 24);

            VSTestCase test3 = AssertTestDetails(tests, QualifiedNameBuilder.FromString("Suit1/Fixturetest_case2"), source);

            AssertSourceDetails(test3, codeFilePath, 30);

            VSTestCase test4 = AssertTestDetails(tests, QualifiedNameBuilder.FromString("Fixturetest_case3"), source);

            AssertSourceDetails(test4, codeFilePath, 37);
        }
        public static VsTestCase ToVsTestCase(this TestCase testCase)
        {
            var vsTestCase = new VsTestCase(testCase.FullyQualifiedName, TestExecutor.ExecutorUri, testCase.Source)
            {
                DisplayName  = testCase.DisplayName,
                CodeFilePath = testCase.CodeFilePath,
                LineNumber   = testCase.LineNumber
            };

            vsTestCase.Traits.AddRange(testCase.Traits.Select(ToVsTrait));

            var property = testCase.Properties.OfType <TestCaseMetaDataProperty>().SingleOrDefault();

            if (property != null)
            {
                vsTestCase.SetPropertyValue(TestMetaDataProperty, property.Serialization);
            }

            return(vsTestCase);
        }
Example #20
0
        public void OneShotBatchTestStrategy()
        {
            var strategy = new OneShotTestBatchStrategy(RunnerFactory, Settings, ArgsBuilder);

            var template = new VSTestCase("test", BoostTestExecutor.ExecutorUri, "source");

            template.SetPropertyValue(VSTestModel.VersionProperty, "1.63.0");
            template.Traits.Add(VSTestModel.TestSuiteTrait, "Master Test Suite");

            var tests = GenerateDummyTests(template, 10).ToList();
            var batch = strategy.BatchTests(tests).ToList();

            Assert.That(batch.Count, Is.EqualTo(1));

            var run = batch.First();

            Assert.That(run.Tests, Is.EqualTo(tests));
            // --run_test should be avoided due to backwards compatibility
            Assert.That(run.Arguments.Tests, Is.Empty);
            // instead, the respective environment variable BOOST_TEST_RUN_FILTERS is to be used
            Assert.That(run.Arguments.Environment.ContainsKey("BOOST_TEST_RUN_FILTERS"), Is.True);
        }
        /// <summary>
        /// Creates a new TestCase object.
        /// </summary>
        /// <param name="sourceExe">Name of the project executable</param>
        /// <param name="sourceInfo">.cpp file path and TestCase line number</param>
        /// <param name="suite">The suite in which testcase is present</param>
        /// <param name="testCaseName">Name of the testcase</param>
        /// <returns>The created TestCase object</returns>
        private static VSTestCase CreateTestCase(string sourceExe, SourceFileInfo sourceInfo, QualifiedNameBuilder suite, string testCaseName)
        {
            suite.Push(testCaseName);

            string qualifiedName = suite.ToString();

            suite.Pop();

            var testCase = new VSTestCase(qualifiedName, BoostTestExecutor.ExecutorUri, sourceExe)
            {
                CodeFilePath = sourceInfo.File,
                LineNumber = sourceInfo.LineNumber,
                DisplayName = testCaseName,
            };

            GroupViaTraits(suite.ToString(), testCase);

            return testCase;
        }
 private void AssertLabelTrait(VSTestCase testCase, string label)
 {
     Assert.That(testCase, Is.Not.Null);
     Assert.That(testCase.Traits.Any((trait) => ((trait.Name == label) && (trait.Value.Length == 0))), Is.True);
 }
Example #23
0
 private void AssertLabelTrait(VSTestCase testCase, string label)
 {
     Assert.That(testCase, Is.Not.Null);
     Assert.That(testCase.Traits.Any((trait) => ((trait.Name == label) && (trait.Value.Length == 0))), Is.True);
 }
 /// <summary>
 /// Helper methods which adds a test case to an internal list and sends the test to the discovery sink
 /// </summary>
 /// <param name="testCase">the test case to be added</param>
 /// <param name="discoverySink">the discovery sink where the test case is sent to</param>
 private static void AddTestCase(VSTestCase testCase, ITestCaseDiscoverySink discoverySink)
 {
     //send to discovery sink
     if (null != discoverySink)
     {
         Logger.Info("Found test: {0}", testCase.FullyQualifiedName);
         discoverySink.SendTestCase(testCase);
     }
 }
        /// <summary>
        /// Asserts general test details for the provided test case
        /// </summary>
        /// <param name="vsTest">The test case to test</param>
        /// <param name="fqn">The expected test case fully qualified name</param>
        /// <param name="source">The expected test case source</param>
        private void AssertTestDetails(VSTestCase vsTest, QualifiedNameBuilder fqn, string source)
        {
            Assert.That(vsTest, Is.Not.Null);
            Assert.That(vsTest.DisplayName, Is.EqualTo(fqn.Peek()));
            Assert.That(vsTest.ExecutorUri, Is.EqualTo(BoostTestExecutor.ExecutorUri));
            Assert.That(vsTest.Source, Is.EqualTo(source));

            string suite = fqn.Pop().ToString();
            if (string.IsNullOrEmpty(suite))
            {
                suite = QualifiedNameBuilder.DefaultMasterTestSuiteName;
            }

            Assert.That(vsTest.Traits.Where((trait) => (trait.Name == VSTestModel.TestSuiteTrait) && (trait.Value == suite)).Count(), Is.EqualTo(1));
        }
        /// <summary>
        /// Asserts source file details for the provided test case
        /// </summary>
        /// <param name="vsTest">The test case to test</param>
        /// <param name="codeFilePath">The expected source file qualified path</param>
        /// <param name="lineNumber">The expected line number for the test case</param>
        private void AssertSourceDetails(VSTestCase vsTest, string codeFilePath, int lineNumber)
        {
            if (vsTest.CodeFilePath != null)
            {
                Assert.That(vsTest.CodeFilePath, Is.EqualTo(codeFilePath));
            }

            if (lineNumber != -1)
            {
                Assert.That(vsTest.LineNumber, Is.EqualTo(lineNumber));
            }
        }
        /// <summary>
        /// Sets the Traits property for the testcase object.
        /// </summary>
        /// <param name="suiteName">Name of the test suite to which the testcase belongs</param>
        /// <param name="testCase">[ref] The testcase object</param>
        private static void GroupViaTraits(string suiteName, VSTestCase testCase)
        {
            string traitName = suiteName;

            if (string.IsNullOrEmpty(suiteName))
            {
                traitName = QualifiedNameBuilder.DefaultMasterTestSuiteName;
            }

            testCase.Traits.Add(VSTestModel.TestSuiteTrait, traitName);
        }