Beispiel #1
0
        public void Sink_ShouldContainTestForAllSupportedTypeOfSources()
        {
            var sources = new[]
            {
                "ListContentSupport" + BoostTestDiscoverer.ExeExtension,
                "DllProject1" + BoostTestDiscoverer.DllExtension,
                "DllProject2" + BoostTestDiscoverer.DllExtension,
            };

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

            context.RegisterSettingProvider(BoostTestAdapterSettings.XmlRootName, new BoostTestAdapterSettingsProvider());
            context.LoadEmbeddedSettings("BoostTestAdapterNunit.Resources.Settings.externalTestRunner.runsettings");

            var boostTestDiscovererFactory = new StubBoostTestDiscovererFactory();

            var boostTestDiscoverer = new BoostTestDiscoverer(boostTestDiscovererFactory);

            boostTestDiscoverer.DiscoverTests(sources, context, logger, sink);

            Assert.That(sink.Tests, Is.Not.Empty);

            // tests are found in the using the fake debughelper
            Assert.That(sink.Tests.Count(x => x.Source == "ListContentSupport" + BoostTestDiscoverer.ExeExtension), Is.EqualTo(8));

            // the external runner does NOT support the two dll projects
            Assert.That(sink.Tests.Any(x => x.Source == "DllProject1" + BoostTestDiscoverer.DllExtension), Is.False);
            Assert.That(sink.Tests.Any(x => x.Source == "DllProject2" + BoostTestDiscoverer.DllExtension), Is.False);
        }
        public void Sink_ShouldContainTestForAllSupportedTypeOfSources()
        {
            var sources = new[]
            {
                "ListContentSupport" + BoostTestDiscoverer.ExeExtension,
                "DllProject1" + BoostTestDiscoverer.DllExtension,
                "DllProject2" + BoostTestDiscoverer.DllExtension,
            };

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

            context.RegisterSettingProvider(BoostTestAdapterSettings.XmlRootName, new BoostTestAdapterSettingsProvider());
            context.LoadEmbeddedSettings("BoostTestAdapterNunit.Resources.Settings.externalTestRunner.runsettings");

            var boostTestDiscovererFactory = new StubBoostTestDiscovererFactory();

            var boostTestDiscoverer = new BoostTestDiscoverer(boostTestDiscovererFactory);
            boostTestDiscoverer.DiscoverTests(sources, context, logger, sink);

            Assert.That(sink.Tests, Is.Not.Empty);

            // tests are found in the using the fake debughelper
            Assert.That(sink.Tests.Count(x => x.Source == "ListContentSupport" + BoostTestDiscoverer.ExeExtension), Is.EqualTo(8));

            // the external runner does NOT support the two dll projects
            Assert.That(sink.Tests.Any(x => x.Source == "DllProject1" + BoostTestDiscoverer.DllExtension), Is.False);
            Assert.That(sink.Tests.Any(x => x.Source == "DllProject2" + BoostTestDiscoverer.DllExtension), Is.False);
        }
        /// <summary>
        /// Discovers all tests cases enumerated within the provided framework
        /// </summary>
        /// <param name="framework">The framework to discover tests from</param>
        /// <returns>An enumeration of all the discovered tests</returns>
        private static IEnumerable <VSTestCase> Discover(TestFramework framework)
        {
            var sink    = new DefaultTestCaseDiscoverySink();
            var visitor = new VSDiscoveryVisitor(framework.Source, sink);

            framework.MasterTestSuite.Apply(visitor);
            return(sink.Tests);
        }
        public void CorrectBoostTestDiscovererDispatching()
        {
            var bootTestDiscovererFactory = A.Fake<IBoostTestDiscovererFactory>();
            var boostDllTestDiscoverer = A.Fake<IBoostTestDiscoverer>();
            var boostExeTestDiscoverer = A.Fake<IBoostTestDiscoverer>();
            var defaultTestContext = new DefaultTestContext();
            var consoleMessageLogger = new ConsoleMessageLogger();
            var defaultTestCaseDiscoverySink = new DefaultTestCaseDiscoverySink();

            ITestDiscoverer boostTestDiscoverer = new BoostTestDiscoverer(bootTestDiscovererFactory);

            var projects = new string[]
            {
                "project1" + BoostTestDiscoverer.DllExtension,
                "project2" + BoostTestDiscoverer.ExeExtension,
                "project3" + BoostTestDiscoverer.ExeExtension,
                "project4" + BoostTestDiscoverer.DllExtension,
                "project5" + BoostTestDiscoverer.DllExtension,
            };

            var dllProjectsExpected = new string[]
            {
                "project1" + BoostTestDiscoverer.DllExtension,
                "project4" + BoostTestDiscoverer.DllExtension,
                "project5" + BoostTestDiscoverer.DllExtension,
            };

            var exeProjectsExpected = new string[]
            {
                "project2" + BoostTestDiscoverer.ExeExtension,
                "project3" + BoostTestDiscoverer.ExeExtension,
            };

            IEnumerable<string> dllProjectsActual = null;
            IEnumerable<string> exeProjectsActual = null;

            A.CallTo(() => bootTestDiscovererFactory.GetTestDiscoverer(BoostTestDiscoverer.DllExtension, A<BoostTestDiscovererFactoryOptions>.Ignored))
                .Returns(boostDllTestDiscoverer);
            A.CallTo(() => bootTestDiscovererFactory.GetTestDiscoverer(BoostTestDiscoverer.ExeExtension, A<BoostTestDiscovererFactoryOptions>.Ignored))
                .Returns(boostExeTestDiscoverer);

            A.CallTo(
                    () =>
                        boostDllTestDiscoverer.DiscoverTests(A<IEnumerable<string>>.Ignored, defaultTestContext,
                            consoleMessageLogger, defaultTestCaseDiscoverySink))
                    .Invokes(call => dllProjectsActual = call.GetArgument<IEnumerable<string>>(0));

            A.CallTo(
                    () =>
                        boostExeTestDiscoverer.DiscoverTests(A<IEnumerable<string>>.Ignored, defaultTestContext,
                            consoleMessageLogger, defaultTestCaseDiscoverySink))
                    .Invokes(call => exeProjectsActual = call.GetArgument<IEnumerable<string>>(0));

            boostTestDiscoverer.DiscoverTests(projects, defaultTestContext, consoleMessageLogger, defaultTestCaseDiscoverySink);

            Assert.AreEqual(dllProjectsExpected, dllProjectsActual);
            Assert.AreEqual(exeProjectsExpected, exeProjectsActual);
        }
        public void ListContentSupport()
        {
            IBoostTestRunner runner = A.Fake <IBoostTestRunner>();

            string output = null;

            A.CallTo(() => runner.Capabilities).Returns(new BoostTestRunnerCapabilities {
                ListContent = true, Version = false
            });
            A.CallTo(() => runner.Execute(A <BoostTestRunnerCommandLineArgs> ._, A <BoostTestRunnerSettings> ._, A <IProcessExecutionContext> ._)).Invokes((call) =>
            {
                BoostTestRunnerCommandLineArgs args = (BoostTestRunnerCommandLineArgs)call.Arguments.First();
                if ((args.ListContent.HasValue) && (args.ListContent.Value == ListContentFormat.DOT))
                {
                    output = TestHelper.CopyEmbeddedResourceToDirectory("BoostTestAdapterNunit.Resources.ListContentDOT.sample.8.list.content.gv", args.StandardErrorFile);
                }
            }).Returns(0);

            FakeBoostTestRunnerFactory factory    = new FakeBoostTestRunnerFactory(runner);
            ListContentDiscoverer      discoverer = new ListContentDiscoverer(factory, DummyVSProvider.Default);

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

            discoverer.DiscoverTests(new[] { "a.exe", }, context, sink);

            // Ensure proper test runner execution
            Assert.That(factory.ProvisionedRunners.Count, Is.EqualTo(1));
            foreach (IBoostTestRunner provisioned in factory.ProvisionedRunners.Select(provision => provision.Item3))
            {
                A.CallTo(() => provisioned.Execute(A <BoostTestRunnerCommandLineArgs> ._, A <BoostTestRunnerSettings> ._, A <IProcessExecutionContext> ._)).
                WhenArgumentsMatch((arguments) =>
                {
                    BoostTestRunnerCommandLineArgs args = (BoostTestRunnerCommandLineArgs)arguments.First();

                    return((args.ListContent.HasValue) &&
                           (args.ListContent.Value == ListContentFormat.DOT) &&
                           (!string.IsNullOrEmpty(args.StandardErrorFile)));
                }).
                MustHaveHappened();
            }

            // Ensure proper test discovery
            Assert.That(sink.Tests.Count, Is.EqualTo(8));

            AssertLabelTrait(sink.Tests.FirstOrDefault((vstest) => (vstest.FullyQualifiedName == "test_2")), "l1");
            AssertLabelTrait(sink.Tests.FirstOrDefault((vstest) => (vstest.FullyQualifiedName == "test_6")), "l1");
            var test_8 = sink.Tests.FirstOrDefault((vstest) => (vstest.FullyQualifiedName == "test_8"));

            AssertLabelTrait(test_8, "l1");
            AssertLabelTrait(test_8, "l2");
            AssertLabelTrait(test_8, "l3 withaspace");

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

            // Ensure proper environment cleanup
            Assert.That(File.Exists(output), Is.False);
        }
        /// <summary>
        /// Applies the discovery procedure over the provided sources
        /// </summary>
        /// <param name="provider">An IVisualStudioInstanceProvider instance</param>
        /// <param name="sources">The sources which to discover tests from</param>
        /// <param name="context">The IDiscoveryContext to use</param>
        /// <returns>An enumeration of discovered test cases</returns>
        private IEnumerable <VSTestCase> Discover(IVisualStudioInstanceProvider provider, IEnumerable <string> sources, IDiscoveryContext context)
        {
            DefaultTestCaseDiscoverySink sink = new DefaultTestCaseDiscoverySink();

            IBoostTestDiscoverer discoverer = new SourceCodeDiscoverer(provider);

            discoverer.DiscoverTests(sources, context, sink);

            return(sink.Tests);
        }
        /// <summary>
        /// Applies the discovery procedure over the provided sources
        /// </summary>
        /// <param name="provider">An IVisualStudioInstanceProvider instance</param>
        /// <param name="sources">The sources which to discover tests from</param>
        /// <param name="context">The IDiscoveryContext to use</param>
        /// <returns>An enumeration of discovered test cases</returns>
        private IEnumerable<VSTestCase> Discover(IVisualStudioInstanceProvider provider, IEnumerable<string> sources, IDiscoveryContext context)
        {
            ConsoleMessageLogger logger = new ConsoleMessageLogger();
            DefaultTestCaseDiscoverySink sink = new DefaultTestCaseDiscoverySink();

            IBoostTestDiscoverer discoverer = new SourceCodeDiscoverer(provider);
            discoverer.DiscoverTests(sources, context, logger, sink);

            return sink.Tests;
        }
        public void ListContentSupport()
        {
            IBoostTestRunner runner = A.Fake<IBoostTestRunner>();

            string output = null;

            A.CallTo(() => runner.ListContentSupported).Returns(true);
            A.CallTo(() => runner.Execute(A<BoostTestRunnerCommandLineArgs>._, A<BoostTestRunnerSettings>._, A<IProcessExecutionContext>._)).Invokes((call) =>
            {
                BoostTestRunnerCommandLineArgs args = (BoostTestRunnerCommandLineArgs) call.Arguments.First();
                if ((args.ListContent.HasValue) && (args.ListContent.Value == ListContentFormat.DOT))
                {
                    output = TestHelper.CopyEmbeddedResourceToDirectory("BoostTestAdapterNunit.Resources.ListContentDOT.sample.8.list.content.gv", args.StandardErrorFile);
                }
            });

            FakeBoostTestRunnerFactory factory = new FakeBoostTestRunnerFactory(runner);
            ListContentDiscoverer discoverer = new ListContentDiscoverer(factory, DummyVSProvider.Default);

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

            discoverer.DiscoverTests(new[] { "a.exe", }, context, sink);

            // Ensure proper test runner execution
            Assert.That(factory.ProvisionedRunners.Count, Is.EqualTo(1));
            foreach (IBoostTestRunner provisioned in factory.ProvisionedRunners.Select(provision => provision.Item3))
            {
                A.CallTo(() => provisioned.Execute(A<BoostTestRunnerCommandLineArgs>._, A<BoostTestRunnerSettings>._, A<IProcessExecutionContext>._)).
                    WhenArgumentsMatch((arguments) =>
                    {
                        BoostTestRunnerCommandLineArgs args = (BoostTestRunnerCommandLineArgs) arguments.First();

                        return (args.ListContent.HasValue) &&
                                (args.ListContent.Value == ListContentFormat.DOT) &&
                                (!string.IsNullOrEmpty(args.StandardErrorFile));
                    }).
                    MustHaveHappened();
            }

            // Ensure proper test discovery
            Assert.That(sink.Tests.Count, Is.EqualTo(8));

            AssertLabelTrait(sink.Tests.FirstOrDefault((vstest) => (vstest.FullyQualifiedName == "test_2")), "l1");
            AssertLabelTrait(sink.Tests.FirstOrDefault((vstest) => (vstest.FullyQualifiedName == "test_6")), "l1");
            var test_8 = sink.Tests.FirstOrDefault((vstest) => (vstest.FullyQualifiedName == "test_8"));
            AssertLabelTrait(test_8, "l1");
            AssertLabelTrait(test_8, "l2");
            AssertLabelTrait(test_8, "l3 withaspace");

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

            // Ensure proper environment cleanup
            Assert.That(File.Exists(output), Is.False);
        }
        /// <summary>
        /// Applies the discovery process over the provided DummySolution
        /// </summary>
        /// <param name="solution">The dummy solution on which to apply test discovery</param>
        /// <returns>The list of tests which were discovered from the dummy solution</returns>
        private IList <TestCase> DiscoverTests(DummySolution solution)
        {
            SourceCodeDiscoverer discoverer = new SourceCodeDiscoverer(solution.Provider);

            DefaultTestContext           context       = new DefaultTestContext();
            DefaultTestCaseDiscoverySink discoverySink = new DefaultTestCaseDiscoverySink();

            discoverer.DiscoverTests(new[] { solution.Source }, context, discoverySink);

            return(discoverySink.Tests.ToList());
        }
        /// <summary>
        /// Applies the discovery process over the provided DummySolution
        /// </summary>
        /// <param name="solution">The dummy solution on which to apply test discovery</param>
        /// <returns>The list of tests which were discovered from the dummy solution</returns>
        private IList<TestCase> DiscoverTests(DummySolution solution)
        {            
            SourceCodeDiscoverer discoverer = new SourceCodeDiscoverer(solution.Provider);

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

            discoverer.DiscoverTests(new[] { solution.Source }, context, logger, discoverySink);
                
            return discoverySink.Tests.ToList();
        }
        public void DiscoveryFileMapDiscovery()
        {
            string listing = TestHelper.CopyEmbeddedResourceToDirectory("BoostTestAdapterNunit.Resources.TestLists", "sample.test.list.xml", Path.GetTempPath());

            try
            {
                ExternalBoostTestRunnerSettings settings = new ExternalBoostTestRunnerSettings
                {
                    ExtensionType = ".dll",
                    DiscoveryMethodType = DiscoveryMethodType.DiscoveryFileMap
                };

                settings.DiscoveryFileMap["test_1.dll"] = listing;

                ExternalBoostTestDiscoverer discoverer = new ExternalBoostTestDiscoverer(settings);

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

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

                discoverer.DiscoverTests(new string[] { mappedSource, unmappedSource }, context, logger, 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));
            }
            finally
            {
                if (File.Exists(listing))
                {
                    File.Delete(listing);
                }
            }
        }
        /// <summary>
        /// Applies the discovery process over the provided DummySolution
        /// </summary>
        /// <param name="solution">The dummy solution on which to apply test discovery</param>
        /// <returns>The list of tests which were discovered from the dummy solution</returns>
        private IList<TestCase> DiscoverTests(DummySolution solution)
        {
            DefaultTestCaseDiscoverySink discoverySink = new DefaultTestCaseDiscoverySink();

            ISourceFilter[] filters = new ISourceFilter[]
            {
                new QuotedStringsFilter(),
                new MultilineCommentFilter(),
                new SingleLineCommentFilter(),
                new ConditionalInclusionsFilter(new ExpressionEvaluation())
            };

            SourceCodeDiscoverer discoverer = new SourceCodeDiscoverer(solution.Provider);
            discoverer.DiscoverTests(new []{solution.Source}, new DefaultTestContext(true), new ConsoleMessageLogger(), discoverySink);

            return discoverySink.Tests.ToList();
        }
        /// <summary>
        /// Applies the discovery process over the provided DummySolution
        /// </summary>
        /// <param name="solution">The dummy solution on which to apply test discovery</param>
        /// <returns>The list of tests which were discovered from the dummy solution</returns>
        private IList <TestCase> DiscoverTests(DummySolution solution)
        {
            DefaultTestCaseDiscoverySink discoverySink = new DefaultTestCaseDiscoverySink();

            ISourceFilter[] filters = new ISourceFilter[]
            {
                new QuotedStringsFilter(),
                new MultilineCommentFilter(),
                new SingleLineCommentFilter(),
                new ConditionalInclusionsFilter(new ExpressionEvaluation())
            };

            SourceCodeDiscoverer discoverer = new SourceCodeDiscoverer(solution.Provider);

            discoverer.DiscoverTests(new [] { solution.Source }, new DefaultTestContext(true), discoverySink);

            return(discoverySink.Tests.ToList());
        }
Beispiel #14
0
        public void FailingExitCode()
        {
            IBoostTestRunner runner = A.Fake <IBoostTestRunner>();

            A.CallTo(() => runner.ListContentSupported).Returns(true);
            A.CallTo(() => runner.VersionSupported).Returns(false);
            A.CallTo(() => runner.Execute(A <BoostTestRunnerCommandLineArgs> ._, A <BoostTestRunnerSettings> ._, A <IProcessExecutionContext> ._)).Returns(-1073741515);

            FakeBoostTestRunnerFactory factory    = new FakeBoostTestRunnerFactory(runner);
            ListContentDiscoverer      discoverer = new ListContentDiscoverer(factory, DummyVSProvider.Default);

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

            discoverer.DiscoverTests(new[] { "missing-dll.exe", }, context, sink);

            // Ensure proper test discovery
            Assert.That(sink.Tests.Count, Is.EqualTo(0));
        }
Beispiel #15
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));
                }
        }
        public void VersionAnnotation()
        {
            IBoostTestRunner runner = A.Fake <IBoostTestRunner>();

            A.CallTo(() => runner.Capabilities).Returns(new BoostTestRunnerCapabilities {
                ListContent = true, Version = true
            });
            A.CallTo(() => runner.Execute(A <BoostTestRunnerCommandLineArgs> ._, A <BoostTestRunnerSettings> ._, A <IProcessExecutionContext> ._)).Invokes((call) =>
            {
                BoostTestRunnerCommandLineArgs args = (BoostTestRunnerCommandLineArgs)call.Arguments.First();

                // --list_content=DOT
                if ((args.ListContent.HasValue) && (args.ListContent.Value == ListContentFormat.DOT) && (!string.IsNullOrEmpty(args.StandardErrorFile)))
                {
                    TestHelper.CopyEmbeddedResourceToDirectory("BoostTestAdapterNunit.Resources.ListContentDOT.sample.3.list.content.gv", args.StandardErrorFile);
                }
                // --version
                else if ((args.Version) && (!string.IsNullOrEmpty(args.StandardErrorFile)))
                {
                    TestHelper.CopyEmbeddedResourceToDirectory("BoostTestAdapterNunit.Resources.Version.sample.version.stderr.log", args.StandardErrorFile);
                }
            }).Returns(0);

            FakeBoostTestRunnerFactory factory    = new FakeBoostTestRunnerFactory(runner);
            ListContentDiscoverer      discoverer = new ListContentDiscoverer(factory, DummyVSProvider.Default);

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

            discoverer.DiscoverTests(new[] { "test.exe", }, context, sink);

            // Ensure proper test discovery
            Assert.That(sink.Tests.Count, Is.Not.EqualTo(0));

            // Ensure that version property is available
            foreach (var test in sink.Tests)
            {
                var version = test.GetPropertyValue(VSTestModel.VersionProperty);
                Assert.That(version, Is.EqualTo("1.63.0"));
            }
        }
        /// <summary>
        /// Execute the tests one by one. Run All.
        /// </summary>
        /// <param name="sources">Collection of test modules (exe/dll)</param>
        /// <param name="runContext">Solution properties</param>
        /// <param name="frameworkHandle">Unit test framework handle</param>
        /// <remarks>Entry point of the execution procedure whenever the user requests to run all the tests</remarks>
        public void RunTests(IEnumerable<string> sources,
            IRunContext runContext,
            IFrameworkHandle frameworkHandle)
        {
            Code.Require(sources, "sources");
            Code.Require(runContext, "runContext");
            Code.Require(frameworkHandle, "frameworkHandle");

            SetUp(frameworkHandle);

            BoostTestAdapterSettings settings = BoostTestAdapterSettingsProvider.GetSettings(runContext);

            foreach (string source in sources)
            {
                if (_cancelled)
                {
                    break;
                }

                var discoverer = _boostTestDiscovererFactory.GetDiscoverer(source, settings);
                if (discoverer != null)
                {
                    try
                    {
                        DefaultTestCaseDiscoverySink sink = new DefaultTestCaseDiscoverySink();

                        // NOTE IRunContext implements IDiscoveryContext
                        // NOTE IFrameworkHandle implements IMessageLogger

                        // Re-discover tests so that we could make use of the RunTests overload which takes an enumeration of test cases.
                        // This is necessary since we need to run tests one by one in order to have the test adapter remain responsive
                        // and have a list of tests over which we can generate test results for.
                        discoverer.DiscoverTests(new[] { source }, runContext, frameworkHandle, sink);

                        // Batch tests into grouped runs based by source so that we avoid reloading symbols per test run
                        // Batching by source since this overload is called when 'Run All...' or equivalent is triggered
                        // NOTE For code-coverage speed is given preference over adapter responsiveness.
                        TestBatch.Strategy strategy = ((runContext.IsDataCollectionEnabled) ? TestBatch.Strategy.Source : settings.TestBatchStrategy);

                        ITestBatchingStrategy batchStrategy = GetBatchStrategy(strategy, settings);
                        if (batchStrategy == null)
                        {
                            Logger.Error("No valid test batching strategy was found for {0}. Source skipped.", source);
                            continue;
                        }

                        IEnumerable<TestRun> batches = batchStrategy.BatchTests(sink.Tests);

                        // Delegate to the RunBoostTests overload which takes an enumeration of test batches
                        RunBoostTests(batches, runContext, frameworkHandle);
                    }
                    catch (Exception ex)
                    {
                        Logger.Error("Exception caught while running tests from {0} ({1})", source, ex.Message);
                    }
                }
            }

            TearDown();
        }
        /// <summary>
        /// Applies the discovery process over the provided DummySolution
        /// </summary>
        /// <param name="solution">The dummy solution on which to apply test discovery</param>
        /// <returns>The list of tests which were discovered from the dummy solution</returns>
        private IList<TestCase> DiscoverTests(DummySolution solution)
        {
            DefaultTestCaseDiscoverySink discoverySink = new DefaultTestCaseDiscoverySink();

            ISourceFilter[] filters = new ISourceFilter[]
            {
                new QuotedStringsFilter(),
                new MultilineCommentFilter(),
                new SingleLineCommentFilter(),
                new ConditionalInclusionsFilter(new ExpressionEvaluation())
            };

            BoostTestDiscovererInternal discoverer = new BoostTestDiscovererInternal(solution.Provider, filters);
            IDictionary<string, ProjectInfo> solutionInfo = discoverer.PrepareTestCaseData(new string[] { solution.Source });
            discoverer.GetBoostTests(solutionInfo, discoverySink);

            return discoverySink.Tests.ToList();
        }
Beispiel #19
0
        /// <summary>
        /// Execute the tests one by one. Run All.
        /// </summary>
        /// <param name="sources">Collection of test modules (exe/dll)</param>
        /// <param name="runContext">Solution properties</param>
        /// <param name="frameworkHandle">Unit test framework handle</param>
        /// <remarks>Entry point of the execution procedure whenever the user requests to run all the tests</remarks>
        public void RunTests(IEnumerable <string> sources,
                             IRunContext runContext,
                             IFrameworkHandle frameworkHandle)
        {
            Code.Require(sources, "sources");
            Code.Require(runContext, "runContext");
            Code.Require(frameworkHandle, "frameworkHandle");

            SetUp(frameworkHandle);

            Logger.Debug("IRunContext.IsDataCollectionEnabled: {0}", runContext.IsDataCollectionEnabled);
            Logger.Debug("IRunContext.RunSettings.SettingsXml: {0}", runContext.RunSettings.SettingsXml);

            BoostTestAdapterSettings settings = BoostTestAdapterSettingsProvider.GetSettings(runContext);

            foreach (string source in sources)
            {
                if (_cancelled)
                {
                    break;
                }

                var discoverer = _boostTestDiscovererFactory.GetDiscoverer(source, settings);
                if (discoverer != null)
                {
                    try
                    {
                        DefaultTestCaseDiscoverySink sink = new DefaultTestCaseDiscoverySink();

                        // NOTE IRunContext implements IDiscoveryContext
                        // NOTE IFrameworkHandle implements IMessageLogger

                        // Re-discover tests so that we could make use of the RunTests overload which takes an enumeration of test cases.
                        // This is necessary since we need to run tests one by one in order to have the test adapter remain responsive
                        // and have a list of tests over which we can generate test results for.
                        discoverer.DiscoverTests(new[] { source }, runContext, sink);

                        // The following ensures that only test cases that are not disabled are run when the user presses "Run all"
                        // This, however, can be overridden by the .runsettings file supplied
                        IEnumerable <TestCase> testsToRun = GetTestsToRun(settings, sink.Tests);

                        // Batch tests into grouped runs based by source so that we avoid reloading symbols per test run
                        // Batching by source since this overload is called when 'Run All...' or equivalent is triggered
                        // NOTE For code-coverage speed is given preference over adapter responsiveness.
                        TestBatch.Strategy strategy = ((runContext.IsDataCollectionEnabled) ? TestBatch.Strategy.Source : settings.TestBatchStrategy);

                        ITestBatchingStrategy batchStrategy = GetBatchStrategy(strategy, settings, runContext);
                        if (batchStrategy == null)
                        {
                            Logger.Error("No valid test batching strategy was found for {0}. Source skipped.", source);
                            continue;
                        }

                        IEnumerable <TestRun> batches = batchStrategy.BatchTests(testsToRun);

                        // Delegate to the RunBoostTests overload which takes an enumeration of test batches
                        RunBoostTests(batches, runContext, frameworkHandle);
                    }
                    catch (Exception ex)
                    {
                        Logger.Error("Exception caught while running tests from {0} ({1})", source, ex.Message);
                    }
                }
            }

            TearDown();
        }