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 "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);
        }
        /// <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);
        }
        /// <summary>
        /// Creates a Visual Studio TestCase based on the provided information
        /// </summary>
        /// <param name="fullyQualifiedName">The fully qualified name of the test case</param>
        /// <param name="source">The test case source</param>
        /// <returns>A Visual Studio TestCase intended for BoostTestExecutor execution</returns>
        private VSTestCase CreateTestCase(string fullyQualifiedName, string source)
        {
            VSTestCase test = new VSTestCase(fullyQualifiedName, BoostTestExecutor.ExecutorUri, source);

            test.Traits.Add(VSTestModel.TestSuiteTrait, QualifiedNameBuilder.FromString(fullyQualifiedName).Pop().ToString());

            return(test);
        }
        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);
            }
        }
        /// <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);
        }
예제 #7
0
        public void DiscoveryFileMapWithInvalidDiscovery()
        {
            using (var listing = TestHelper.CopyEmbeddedResourceToTempDirectory("BoostTestAdapterNunit.Resources.TestLists", "sample.test.list.xml"))
                using (var invalid_listing = TestHelper.CopyEmbeddedResourceToTempDirectory("BoostTestAdapterNunit.Resources.TestLists", "invalid.test.list.xml"))
                {
                    ExternalBoostTestRunnerSettings settings = new ExternalBoostTestRunnerSettings
                    {
                        DiscoveryMethodType = DiscoveryMethodType.DiscoveryFileMap
                    };

                    settings.DiscoveryFileMap["test_2.dll"] = invalid_listing.Path;
                    settings.DiscoveryFileMap["test_1.dll"] = listing.Path;

                    ExternalDiscoverer discoverer = new ExternalDiscoverer(settings, DummyVSProvider.Default);

                    DefaultTestContext           context = new DefaultTestContext();
                    ConsoleMessageLogger         logger  = new ConsoleMessageLogger();
                    DefaultTestCaseDiscoverySink sink    = new DefaultTestCaseDiscoverySink();

                    const string mappedSource  = "C:\\test_1.dll";
                    const string invalidSource = "C:\\test_2.dll";

                    discoverer.DiscoverTests(new string[] { mappedSource, invalidSource }, context, sink);

                    // A total of 7 tests should be discovered as described in the Xml descriptor
                    Assert.That(sink.Tests.Count(), Is.EqualTo(7));

                    // All of the discovered tests should originate from C:\test_1.dll.
                    // No mapping to C:\test_2.dll exist so no tests should be discovered from that source.
                    Assert.That(sink.Tests.Count((test) => test.Source == mappedSource), Is.EqualTo(7));

                    const string masterTestSuite = "Test runner test";

                    AssertVSTestCaseProperties(sink.Tests, QualifiedNameBuilder.FromString(masterTestSuite, "test1"), mappedSource, new SourceFileInfo("test_runner_test.cpp", 26));
                    AssertVSTestCaseProperties(sink.Tests, QualifiedNameBuilder.FromString(masterTestSuite, "test2"), mappedSource, new SourceFileInfo("test_runner_test.cpp", 35));
                    AssertVSTestCaseProperties(sink.Tests, QualifiedNameBuilder.FromString(masterTestSuite, "SampleSuite/SampleNestedSuite/test3"), mappedSource, new SourceFileInfo("test_runner_test.cpp", 48));
                    AssertVSTestCaseProperties(sink.Tests, QualifiedNameBuilder.FromString(masterTestSuite, "TemplateSuite/my_test<char>"), mappedSource, new SourceFileInfo("test_runner_test.cpp", 79));
                    AssertVSTestCaseProperties(sink.Tests, QualifiedNameBuilder.FromString(masterTestSuite, "TemplateSuite/my_test<int>"), mappedSource, new SourceFileInfo("test_runner_test.cpp", 79));
                    AssertVSTestCaseProperties(sink.Tests, QualifiedNameBuilder.FromString(masterTestSuite, "TemplateSuite/my_test<float>"), mappedSource, new SourceFileInfo("test_runner_test.cpp", 79));
                    AssertVSTestCaseProperties(sink.Tests, QualifiedNameBuilder.FromString(masterTestSuite, "TemplateSuite/my_test<double>"), mappedSource, new SourceFileInfo("test_runner_test.cpp", 79));
                }
        }
예제 #8
0
 /// <summary>
 /// Given a fully qualified name of a <b>test case</b>, generates the respective test unit hierarchy.
 /// </summary>
 /// <param name="fullyQualifiedName">The fully qualified name of the <b>test case</b></param>
 /// <returns>The test case hierarcy represented by the provided fully qualified name</returns>
 public static TestCase FromFullyQualifiedName(string fullyQualifiedName)
 {
     return(FromFullyQualifiedName(QualifiedNameBuilder.FromString(fullyQualifiedName)));
 }
        public override IEnumerable <TestRun> BatchTests(IEnumerable <VSTestCase> tests)
        {
            BoostTestRunnerSettings adaptedSettings = this.Settings.TestRunnerSettings.Clone();

            // Disable timeout since this batching strategy executes more than one test at a time
            adaptedSettings.Timeout = -1;

            // Group by source
            IEnumerable <IGrouping <string, VSTestCase> > sources = tests.GroupBy(test => test.Source);

            foreach (IGrouping <string, VSTestCase> source in sources)
            {
                IBoostTestRunner runner = GetTestRunner(source.Key);
                if (runner == null)
                {
                    continue;
                }

                // Group by test suite
                var suiteGroups = source.GroupBy(test => test.Traits.First(trait => (trait.Name == VSTestModel.TestSuiteTrait)).Value);
                foreach (var suiteGroup in suiteGroups)
                {
                    BoostTestRunnerCommandLineArgs args = BuildCommandLineArgs(source.Key);
                    foreach (VSTestCase test in suiteGroup)
                    {
                        // List all tests by name but ensure that the first test is fully qualified so that remaining tests are taken relative to this test suite
                        args.Tests.Add((args.Tests.Count == 0) ? test.FullyQualifiedName : QualifiedNameBuilder.FromString(test.FullyQualifiedName).Peek());
                    }

                    yield return(new TestRun(runner, suiteGroup, args, adaptedSettings));
                }
            }
        }