Exemplo n.º 1
0
        public void CorrectMultipleBoostTestDiscovererDispatchingWithExternalExe()
        {
            var sources = new[]
            {
                "ListContentSupport" + BoostTestDiscoverer.ExeExtension,
                "ParseSources1" + BoostTestDiscoverer.ExeExtension,
                "ParseSources2" + BoostTestDiscoverer.ExeExtension,
                "DllProject1" + BoostTestDiscoverer.DllExtension,
                "DllProject2" + BoostTestDiscoverer.DllExtension,
            };

            BoostTestAdapterSettings settings = CreateAdapterSettings();

            settings.ExternalTestRunner = CreateExternalRunnerSettings(BoostTestDiscoverer.ExeExtension);

            var results = this.DiscovererFactory.GetDiscoverers(sources, settings);

            Assert.That(results.Count(), Is.EqualTo(1));
            Assert.That(results.FirstOrDefault(x => x.Discoverer is ListContentDiscoverer), Is.Null);
            Assert.That(results.FirstOrDefault(x => x.Discoverer is SourceCodeDiscoverer), Is.Null);
            Assert.That(results.FirstOrDefault(x => x.Discoverer is ExternalDiscoverer), Is.Not.Null);

            var exd = results.First(x => x.Discoverer is ExternalDiscoverer);

            Assert.That(exd.Sources, Is.EqualTo(new[] { "ListContentSupport" + BoostTestDiscoverer.ExeExtension,
                                                        "ParseSources1" + BoostTestDiscoverer.ExeExtension,
                                                        "ParseSources2" + BoostTestDiscoverer.ExeExtension, }));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Provides a collection of ISourceFilters based on the provided BoostTestAdapterSettings.
        /// </summary>
        /// <param name="settings">The BoostTestAdapterSettings</param>
        /// <returns>An collection of ISourceFilters based on the provided settings.</returns>
        public static ISourceFilter[] Get(BoostTestAdapterSettings settings)
        {
            Utility.Code.Require(settings, "settings");

            if (settings.ConditionalInclusionsFilteringEnabled)
            {
                return(new ISourceFilter[]
                {
                    new QuotedStringsFilter(),
                    new MultilineCommentFilter(),
                    new SingleLineCommentFilter(),
                    new ConditionalInclusionsFilter(
                        new ExpressionEvaluation()
                        )
                });
            }
            else
            {
                Logger.Warn("Conditional inclusions filtering is disabled.");

                return(new ISourceFilter[]
                {
                    new QuotedStringsFilter(),
                    new MultilineCommentFilter(),
                    new SingleLineCommentFilter(),
                    //conditional inclusions filter omitted
                });
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Parses the Xml report and log file as specified within the provided
        /// BoostTestRunnerCommandLineArgs instance.
        /// </summary>
        /// <param name="args">The BoostTestRunnerCommandLineArgs which specify the report and log file.</param>
        /// <param name="settings">The BoostTestAdapterSettings which specify adapter specific settings.</param>
        public void Parse(BoostTestRunnerCommandLineArgs args, BoostTestAdapterSettings settings)
        {
            IEnumerable <IBoostTestResultOutput> parsers = Enumerable.Empty <IBoostTestResultOutput>();

            try
            {
                parsers = new IBoostTestResultOutput[] {
                    GetReportParser(args),
                    GetLogParser(args),
                    GetStandardOutput(args, settings),
                    GetStandardError(args, settings)
                };

                Parse(parsers);
            }
            finally
            {
                foreach (IBoostTestResultOutput parser in parsers)
                {
                    if (parser != null)
                    {
                        parser.Dispose();
                    }
                }
            }
        }
Exemplo n.º 4
0
        public void CorrectSingleProjectBoostTestDiscovererDispatchingExternalDll()
        {
            BoostTestAdapterSettings settings = CreateAdapterSettings();

            settings.ExternalTestRunner = CreateExternalRunnerSettings(BoostTestDiscoverer.DllExtension);

            // source that supports --list-content parameter
            var source     = "ListContentSupport" + BoostTestDiscoverer.ExeExtension;
            var discoverer = this.DiscovererFactory.GetDiscoverer(source, settings);

            Assert.That(discoverer, Is.Not.Null);
            Assert.That(discoverer, Is.AssignableFrom(typeof(ListContentDiscoverer)));

            // source that NOT supports --list-content parameter
            source     = "ParseSources" + BoostTestDiscoverer.ExeExtension;
            discoverer = this.DiscovererFactory.GetDiscoverer(source, settings);

            Assert.That(discoverer, Is.Not.Null);
            Assert.That(discoverer, Is.AssignableFrom(typeof(SourceCodeDiscoverer)));

            // source dll project
            source     = "DllProject" + BoostTestDiscoverer.DllExtension;
            discoverer = this.DiscovererFactory.GetDiscoverer(source, settings);

            Assert.That(discoverer, Is.Not.Null);
            Assert.That(discoverer, Is.AssignableFrom(typeof(ExternalDiscoverer)));
        }
Exemplo n.º 5
0
        public void SetUp()
        {
            RunnerFactory = A.Fake <IBoostTestRunnerFactory>();
            A.CallTo(() => RunnerFactory.GetRunner(A <string> ._, A <BoostTestRunnerFactoryOptions> ._)).Returns(A.Fake <IBoostTestRunner>());

            Settings = new BoostTestAdapterSettings();

            ArgsBuilder = (string source, BoostTestAdapterSettings settings) => { return(new BoostTestRunnerCommandLineArgs()); };
        }
        /// <summary>
        /// Run tests one test at a time and update results back to framework.
        /// </summary>
        /// <param name="testBatches">List of test batches to run</param>
        /// <param name="runContext">Solution properties</param>
        /// <param name="frameworkHandle">Unit test framework handle</param>
        private void RunBoostTests(IEnumerable <TestRun> testBatches, IRunContext runContext, IFrameworkHandle frameworkHandle)
        {
            BoostTestAdapterSettings settings = BoostTestAdapterSettingsProvider.GetSettings(runContext);

            foreach (TestRun batch in testBatches)
            {
                if (_cancelled)
                {
                    break;
                }

                DateTimeOffset start = new DateTimeOffset(DateTime.Now);

                try
                {
                    Logger.Info("{0}:   -> [{1}]", ((runContext.IsBeingDebugged) ? "Debugging" : "Executing"), string.Join(", ", batch.Tests));

                    using (TemporaryFile report = new TemporaryFile(batch.Arguments.ReportFile))
                        using (TemporaryFile log = new TemporaryFile(batch.Arguments.LogFile))
                            using (TemporaryFile stdout = new TemporaryFile(batch.Arguments.StandardOutFile))
                                using (TemporaryFile stderr = new TemporaryFile(batch.Arguments.StandardErrorFile))
                                {
                                    Logger.Debug("Working directory: {0}", batch.Arguments.WorkingDirectory ?? "(null)");
                                    Logger.Debug("Report file      : {0}", batch.Arguments.ReportFile);
                                    Logger.Debug("Log file         : {0}", batch.Arguments.LogFile);
                                    Logger.Debug("StdOut file      : {0}", batch.Arguments.StandardOutFile ?? "(null)");
                                    Logger.Debug("StdErr file      : {0}", batch.Arguments.StandardErrorFile ?? "(null)");

                                    // Execute the tests
                                    if (ExecuteTests(batch, runContext, frameworkHandle))
                                    {
                                        foreach (VSTestResult result in GenerateTestResults(batch, start, settings))
                                        {
                                            // Identify test result to Visual Studio Test framework
                                            frameworkHandle.RecordResult(result);
                                        }
                                    }
                                }
                }
                catch (Boost.Runner.TimeoutException ex)
                {
                    foreach (VSTestCase testCase in batch.Tests)
                    {
                        VSTestResult testResult = GenerateTimeoutResult(testCase, ex);
                        testResult.StartTime = start;

                        frameworkHandle.RecordResult(testResult);
                    }
                }
                catch (Exception ex)
                {
                    Logger.Exception(ex, "Exception caught while running test batch {0} [{1}] ({2})", batch.Source, string.Join(", ", batch.Tests), ex.Message);
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Determines whether the provided source has --list_content capabilities
        /// </summary>
        /// <param name="source">The source to test</param>
        /// <param name="settings">Test adapter settings</param>
        /// <returns>true if the source has list content capabilities; false otherwise</returns>
        private bool IsListContentSupported(string source, BoostTestAdapterSettings settings)
        {
            BoostTestRunnerFactoryOptions options = new BoostTestRunnerFactoryOptions()
            {
                ExternalTestRunnerSettings = settings.ExternalTestRunner
            };

            IBoostTestRunner runner = _factory.GetRunner(source, options);

            return((runner != null) && runner.ListContentSupported);
        }
 /// <summary>
 /// Retrieves and assigns parameters by resolving configurations from different possible resources
 /// </summary>
 /// <param name="source">The TestCases source</param>
 /// <param name="settings">The Boost Test adapter settings currently in use</param>
 /// <returns>A string for the default working directory</returns>
 private void GetDebugConfigurationProperties(string source, BoostTestAdapterSettings settings, BoostTestRunnerCommandLineArgs args)
 {
     try
     {
         args.SetWorkingEnvironment(source, settings, ((_vsProvider == null) ? null : _vsProvider.Instance));
     }
     catch (COMException ex)
     {
         Logger.Exception(ex, "Could not retrieve WorkingDirectory from Visual Studio Configuration-{0}", ex.Message);
     }
 }
Exemplo n.º 9
0
        /// <summary>
        /// Determines whether the provided source has --list_content capabilities
        /// </summary>
        /// <param name="source">The source to test</param>
        /// <param name="settings">Test adapter settings</param>
        /// <returns>true if the source has list content capabilities; false otherwise</returns>
        private bool IsListContentSupported(string source, BoostTestAdapterSettings settings)
        {
            BoostTestRunnerFactoryOptions options = new BoostTestRunnerFactoryOptions()
            {
                ExternalTestRunnerSettings = settings.ExternalTestRunner
            };

            IBoostTestRunner runner = _factory.GetRunner(source, options);

            // Convention over configuration. Assume test runners utilising such an extension
            return((runner != null) && (runner.Source.EndsWith(ForceListContentExtension, StringComparison.OrdinalIgnoreCase) || runner.ListContentSupported));
        }
Exemplo n.º 10
0
        public void ParseSampleSettings()
        {
            BoostTestAdapterSettings settings = ParseEmbeddedResource("BoostTestAdapterNunit.Resources.Settings.sample.runsettings");

            Assert.That(settings.ExecutionTimeoutMilliseconds, Is.EqualTo(600000));
            Assert.That(settings.DiscoveryTimeoutMilliseconds, Is.EqualTo(600000));
            Assert.That(settings.FailTestOnMemoryLeak, Is.True);

            Assert.That(settings.ExternalTestRunner, Is.Not.Null);
            Assert.That(settings.ExternalTestRunner.ExtensionType.ToString(), Is.EqualTo(".dll"));
            Assert.That(settings.ExternalTestRunner.ExecutionCommandLine.ToString(), Is.EqualTo("C:\\ExternalTestRunner.exe --test {source} "));
        }
        /// <summary>
        /// Compares the serialized content of the settings structure against an Xml embedded resource string.
        /// </summary>
        /// <param name="settings">The settings structure whose serialization is to be compared</param>
        /// <param name="resource">The path to an embedded resource which contains the serialized Xml content to compare against</param>
        private void Compare(BoostTestAdapterSettings settings, string resource)
        {
            XmlElement element = settings.ToXml();

            using (Stream stream = TestHelper.LoadEmbeddedResource(resource))
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(stream);

                XmlNode root = doc.DocumentElement.SelectSingleNode("/RunSettings/BoostTest");

                XmlComparer comparer = new XmlComparer();
                comparer.CompareXML(element, root, XmlNodeTypeFilter.DefaultFilter);
            }
        }
        public void SerialiseExternalTestRunnerDiscoveryMapSettings()
        {
            BoostTestAdapterSettings settings = new BoostTestAdapterSettings();

            settings.ExternalTestRunner = new ExternalBoostTestRunnerSettings
            {
                DiscoveryMethodType  = DiscoveryMethodType.DiscoveryFileMap,
                ExecutionCommandLine = new CommandLine("C:\\ExternalTestRunner.exe", "--test \"{source}\"")
            };

            settings.ExternalTestRunner.DiscoveryFileMap.Add("test_1.dll", "C:\\tests\\test_1.xml");
            settings.ExternalTestRunner.DiscoveryFileMap.Add("test_2.dll", "C:\\tests\\test_2.xml");

            Compare(settings, "BoostTestAdapterNunit.Resources.Settings.externalTestRunner.runsettings");
        }
        public void SerializeSettings()
        {
            BoostTestAdapterSettings settings = new BoostTestAdapterSettings();

            settings.ExecutionTimeoutMilliseconds = 600000;
            settings.DiscoveryTimeoutMilliseconds = 600000;
            settings.FailTestOnMemoryLeak         = true;

            settings.ExternalTestRunner = new ExternalBoostTestRunnerSettings()
            {
                DiscoveryMethodType  = DiscoveryMethodType.DiscoveryCommandLine,
                DiscoveryCommandLine = new CommandLine("C:\\ExternalTestRunner.exe", "--test \"{source}\" --list-debug \"{out}\""),
                ExecutionCommandLine = new CommandLine("C:\\ExternalTestRunner.exe", "--test \"{source}\"")
            };

            Compare(settings, "BoostTestAdapterNunit.Resources.Settings.sample.runsettings");
        }
 /// <summary>
 /// Tests the contents of a BoostTestAdapterSettings instance, making sure they comply to the default expected values.
 /// </summary>
 /// <param name="settings">The BoostTestAdapterSettings instance to test</param>
 private void AssertDefaultSettings(BoostTestAdapterSettings settings)
 {
     Assert.That(settings.ExecutionTimeoutMilliseconds, Is.EqualTo(-1));
     Assert.That(settings.DiscoveryTimeoutMilliseconds, Is.EqualTo(30000));
     Assert.That(settings.FailTestOnMemoryLeak, Is.False);
     Assert.That(settings.ConditionalInclusionsFilteringEnabled, Is.True);
     Assert.That(settings.LogLevel, Is.EqualTo(LogLevel.TestSuite));
     Assert.That(settings.ExternalTestRunner, Is.Null);
     Assert.That(settings.DetectFloatingPointExceptions, Is.False);
     Assert.That(settings.CatchSystemErrors, Is.True);
     Assert.That(settings.TestBatchStrategy, Is.EqualTo(Strategy.TestCase));
     Assert.That(settings.UseListContent, Is.True);
     Assert.That(settings.ForceListContent, Is.False);
     Assert.That(settings.WorkingDirectory, Is.Null);
     Assert.That(settings.EnableStdOutRedirection, Is.True);
     Assert.That(settings.EnableStdErrRedirection, Is.True);
     Assert.That(settings.Filters, Is.EqualTo(TestSourceFilter.Empty));
 }
        /// <summary>
        /// Provides a test batching strategy based on the provided arguments
        /// </summary>
        /// <param name="strategy">The base strategy to provide</param>
        /// <param name="settings">Adapter settings currently in use</param>
        /// <returns>An ITestBatchingStrategy instance or null if one cannot be provided</returns>
        private ITestBatchingStrategy GetBatchStrategy(TestBatch.Strategy strategy, BoostTestAdapterSettings settings)
        {
            TestBatch.CommandLineArgsBuilder argsBuilder = GetDefaultArguments;
            if (strategy != Strategy.TestCase)
            {
                argsBuilder = GetBatchedTestRunsArguments;
            }

            switch (strategy)
            {
            case Strategy.Source: return(new SourceTestBatchStrategy(this._testRunnerFactory, settings, argsBuilder));

            case Strategy.TestSuite: return(new TestSuiteTestBatchStrategy(this._testRunnerFactory, settings, argsBuilder));

            case Strategy.TestCase: return(new IndividualTestBatchStrategy(this._testRunnerFactory, settings, argsBuilder));
            }

            return(null);
        }
        /// <summary>
        /// Factory function which returns an appropriate BoostTestRunnerCommandLineArgs structure
        /// </summary>
        /// <param name="source">The TestCases source</param>
        /// <param name="settings">The Boost Test adapter settings currently in use</param>
        /// <returns>A BoostTestRunnerCommandLineArgs structure for the provided source</returns>
        private BoostTestRunnerCommandLineArgs GetDefaultArguments(string source, BoostTestAdapterSettings settings)
        {
            BoostTestRunnerCommandLineArgs args = settings.CommandLineArgs.Clone();

            GetDebugConfigurationProperties(source, settings, args);

            // Specify log and report file information
            args.LogFormat = OutputFormat.XML;
            args.LogLevel  = settings.LogLevel;
            args.LogFile   = TestPathGenerator.Generate(source, FileExtensions.LogFile);

            args.ReportFormat = OutputFormat.XML;
            args.ReportLevel  = ReportLevel.Detailed;
            args.ReportFile   = TestPathGenerator.Generate(source, FileExtensions.ReportFile);

            args.StandardOutFile   = ((settings.EnableStdOutRedirection) ? TestPathGenerator.Generate(source, FileExtensions.StdOutFile) : null);
            args.StandardErrorFile = ((settings.EnableStdErrRedirection) ? TestPathGenerator.Generate(source, FileExtensions.StdErrFile) : null);

            return(args);
        }
        public Type TestDiscovererProvisioning(string source, string externalExtension)
        {
            ExternalBoostTestRunnerSettings externalSettings = null;

            if (!string.IsNullOrEmpty(externalExtension))
            {
                externalSettings = new ExternalBoostTestRunnerSettings {
                    ExtensionType = new Regex(externalExtension)
                };
            }

            BoostTestAdapterSettings settings = new BoostTestAdapterSettings()
            {
                ExternalTestRunner = externalSettings
            };

            IBoostTestDiscoverer discoverer = this.DiscovererFactory.GetDiscoverer(source, settings);

            return((discoverer == null) ? null : discoverer.GetType());
        }
Exemplo n.º 18
0
        public void ParseComplexSettings()
        {
            BoostTestAdapterSettings settings = ParseEmbeddedResource("BoostTestAdapterNunit.Resources.Settings.sample.2.runsettings");

            Assert.That(settings.ExecutionTimeoutMilliseconds, Is.EqualTo(100));
            Assert.That(settings.DiscoveryTimeoutMilliseconds, Is.EqualTo(100));

            Assert.That(settings.CatchSystemErrors, Is.False);
            Assert.That(settings.DetectFloatingPointExceptions, Is.True);
            Assert.That(settings.TestBatchStrategy, Is.EqualTo(Strategy.TestSuite));

            Assert.That(settings.RunDisabledTests, Is.True);

            Assert.That(settings.Filters, Is.Not.Null);
            Assert.That(settings.Filters.Include, Is.Not.Empty);
            Assert.That(settings.Filters.Include, Is.EquivalentTo(new[] { "mytest.exe$" }));

            Assert.That(settings.Filters.Exclude, Is.Not.Empty);
            Assert.That(settings.Filters.Exclude, Is.EquivalentTo(new[] { "test.exe$" }));
        }
Exemplo n.º 19
0
        /// <summary>
        /// Execute the tests one by one. Run Selected
        /// </summary>
        /// <param name="tests">Testcases object</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 one or a specific lists of tests</remarks>
        public void RunTests(IEnumerable <VSTestCase> tests, IRunContext runContext, IFrameworkHandle frameworkHandle)
        {
            Code.Require(tests, "tests");
            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);

            // Batch tests into grouped runs based on test source and test suite so that we minimize symbol reloading
            //
            // NOTE Required batching at test suite level since Boost Unit Test Framework command-line arguments only allow
            //      multiple test name specification for tests which reside in the same test suite
            //
            // NOTE For code-coverage speed is given preference over adapter responsiveness.
            TestBatch.Strategy strategy = ((runContext.IsDataCollectionEnabled) ? TestBatch.Strategy.TestSuite : settings.TestBatchStrategy);
            // Source strategy is invalid in such context since explicit tests are chosen. TestSuite is used instead.
            if (strategy == Strategy.Source)
            {
                strategy = Strategy.TestSuite;
            }

            ITestBatchingStrategy batchStrategy = GetBatchStrategy(strategy, settings, runContext);

            if (batchStrategy == null)
            {
                Logger.Error("No valid test batching strategy was found. Tests skipped.");
            }
            else
            {
                // NOTE Apply distinct to avoid duplicate test cases. Common issue when using BOOST_DATA_TEST_CASE.
                IEnumerable <TestRun> batches = batchStrategy.BatchTests(tests.Distinct(new TestCaseComparer()));
                RunBoostTests(batches, runContext, frameworkHandle);
            }

            TearDown();
        }
Exemplo n.º 20
0
        /// <summary>
        /// Retrieves and assigns parameters by resolving configurations from different possible resources
        /// </summary>
        /// <param name="source">The TestCases source</param>
        /// <param name="settings">The Boost Test adapter settings currently in use</param>
        /// <returns>A string for the default working directory</returns>
        private void GetDebugConfigurationProperties(string source, BoostTestAdapterSettings settings, BoostTestRunnerCommandLineArgs args)
        {
            try
            {
                var vs = _vsProvider?.Instance;
                if (vs != null)
                {
                    Logger.Debug("Connected to Visual Studio {0} instance", vs.Version);
                }

                args.SetWorkingEnvironment(source, settings, vs);
            }
            catch (ROTException ex)
            {
                Logger.Exception(ex, "Could not retrieve WorkingDirectory from Visual Studio Configuration");
            }
            catch (COMException ex)
            {
                Logger.Exception(ex, "Could not retrieve WorkingDirectory from Visual Studio Configuration-{0}", ex.Message);
            }
        }
Exemplo n.º 21
0
        /// <summary>
        /// Filters out any tests which are not intended to run
        /// </summary>
        /// <param name="settings">Adapter settings which determines test filtering</param>
        /// <param name="tests">The entire test corpus</param>
        /// <returns>A test corpus which contains only the test which are intended to run</returns>
        private static IEnumerable <VSTestCase> GetTestsToRun(BoostTestAdapterSettings settings, IEnumerable <VSTestCase> tests)
        {
            IEnumerable <VSTestCase> testsToRun = tests;

            if (!settings.RunDisabledTests)
            {
                testsToRun = tests.Where((test) =>
                {
                    foreach (var trait in test.Traits)
                    {
                        if ((trait.Name == VSTestModel.StatusTrait) && (trait.Value == VSTestModel.TestEnabled))
                        {
                            return(true);
                        }
                    }

                    return(false);
                });
            }

            return(testsToRun);
        }
Exemplo n.º 22
0
        /// <summary>
        /// Provides a test batching strategy based on the provided arguments
        /// </summary>
        /// <param name="strategy">The base strategy to provide</param>
        /// <param name="settings">Adapter settings currently in use</param>
        /// <param name="runContext">The RunContext for this TestCase. Determines whether the test should be debugged or not.</param>
        /// <returns>An ITestBatchingStrategy instance or null if one cannot be provided</returns>
        private ITestBatchingStrategy GetBatchStrategy(TestBatch.Strategy strategy, BoostTestAdapterSettings settings, IRunContext runContext)
        {
            TestBatch.CommandLineArgsBuilder argsBuilder = (string _source, BoostTestAdapterSettings _settings) =>
            {
                return(GetDefaultArguments(_source, _settings, runContext.IsBeingDebugged));
            };

            if (strategy != Strategy.TestCase)
            {
                // Disable stdout, stderr and memory leak detection since it is difficult
                // to distinguish from which test does portions of the output map to
                argsBuilder = (string _source, BoostTestAdapterSettings _settings) =>
                {
                    var args = GetDefaultArguments(_source, _settings, runContext.IsBeingDebugged);

                    // Disable standard error/standard output capture
                    args.StandardOutFile   = null;
                    args.StandardErrorFile = null;

                    // Disable memory leak detection
                    args.DetectMemoryLeaks = 0;

                    return(args);
                };
            }

            switch (strategy)
            {
            case Strategy.Source: return(new SourceTestBatchStrategy(_testRunnerFactory, settings, argsBuilder));

            case Strategy.TestSuite: return(new TestSuiteTestBatchStrategy(_testRunnerFactory, settings, argsBuilder));

            case Strategy.TestCase: return(new IndividualTestBatchStrategy(_testRunnerFactory, settings, argsBuilder));

            case Strategy.One: return(new OneShotTestBatchStrategy(_testRunnerFactory, settings, argsBuilder));
            }

            return(null);
        }
        public void DiscoverTests(IEnumerable <string> sources, IDiscoveryContext discoveryContext, ITestCaseDiscoverySink discoverySink)
        {
            if (sources == null)
            {
                return;
            }

            BoostTestAdapterSettings settings = BoostTestAdapterSettingsProvider.GetSettings(discoveryContext);

            try
            {
                // Filter out any sources which are not of interest
                if (!TestSourceFilter.IsNullOrEmpty(settings.Filters))
                {
                    sources = sources.Where(settings.Filters.ShouldInclude);
                }

                var results = _boostTestDiscovererFactory.GetDiscoverers(sources.ToList(), settings);
                if (results == null)
                {
                    return;
                }

                // Test discovery
                foreach (var discoverer in results)
                {
                    if (discoverer.Sources.Count > 0)
                    {
                        Logger.Info("Discovering ({0}):   -> [{1}]", discoverer.Discoverer.GetType().Name, string.Join(", ", discoverer.Sources));
                        discoverer.Discoverer.DiscoverTests(discoverer.Sources, discoveryContext, discoverySink);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Exception(ex, "Exception caught while discovering tests: {0} ({1})", ex.Message, ex.HResult);
            }
        }
        public void ParseExternalTestRunnerDiscoveryMapSettings()
        {
            BoostTestAdapterSettings settings = Parse("BoostTestAdapterNunit.Resources.Settings.externalTestRunner.runsettings");

            Assert.That(settings.ExecutionTimeoutMilliseconds, Is.EqualTo(-1));
            Assert.That(settings.DiscoveryTimeoutMilliseconds, Is.EqualTo(30000));
            Assert.That(settings.FailTestOnMemoryLeak, Is.False);
            Assert.That(settings.ConditionalInclusionsFilteringEnabled, Is.True);
            Assert.That(settings.LogLevel, Is.EqualTo(LogLevel.TestSuite));
            Assert.That(settings.ExternalTestRunner, Is.Not.Null);

            Assert.That(settings.ExternalTestRunner.ExtensionType.ToString(), Is.EqualTo(".dll"));
            Assert.That(settings.ExternalTestRunner.DiscoveryMethodType, Is.EqualTo(DiscoveryMethodType.DiscoveryFileMap));

            IDictionary <string, string> fileMap = new Dictionary <string, string>
            {
                { "test_1.dll", "C:\\tests\\test_1.xml" },
                { "test_2.dll", "C:\\tests\\test_2.xml" }
            };

            Assert.That(settings.ExternalTestRunner.DiscoveryFileMap, Is.EqualTo(fileMap));
            Assert.That(settings.ExternalTestRunner.ExecutionCommandLine.ToString(), Is.EqualTo("C:\\ExternalTestRunner.exe --test {source} "));
        }
        public void DiscoverTests(IEnumerable <string> sources, IDiscoveryContext discoveryContext, ITestCaseDiscoverySink discoverySink)
        {
            Code.Require(sources, "sources");
            Code.Require(discoverySink, "discoverySink");

            BoostTestAdapterSettings settings = BoostTestAdapterSettingsProvider.GetSettings(discoveryContext);

            _sourceFilters = SourceFilterFactory.Get(settings);
            IDictionary <string, ProjectInfo> solutioninfo = null;

            var numberOfAttempts = 100;

            // try several times to overcome "Application is Busy" COMException
            while (numberOfAttempts > 0)
            {
                try
                {
                    solutioninfo = PrepareTestCaseData(sources);
                    // set numberOfAttempts = 0, because there is no need to try again,
                    // since obviously no exception was thrown at this point
                    numberOfAttempts = 0;
                }
                catch (COMException)
                {
                    --numberOfAttempts;

                    // re-throw after all attempts have failed
                    if (numberOfAttempts == 0)
                    {
                        throw;
                    }
                }
            }

            GetBoostTests(solutioninfo, discoverySink);
        }
Exemplo n.º 26
0
        /// <summary>
        /// Factory function which returns an appropriate BoostTestRunnerCommandLineArgs structure
        /// </summary>
        /// <param name="source">The TestCases source</param>
        /// <param name="settings">The Boost Test adapter settings currently in use</param>
        /// <param name="debugMode">Determines whether the test should be debugged or not.</param>
        /// <returns>A BoostTestRunnerCommandLineArgs structure for the provided source</returns>
        private BoostTestRunnerCommandLineArgs GetDefaultArguments(string source, BoostTestAdapterSettings settings, bool debugMode)
        {
            BoostTestRunnerCommandLineArgs args = settings.CommandLineArgs.Clone();

            GetDebugConfigurationProperties(source, settings, args);

            // Specify log and report file information
            args.LogFormat = OutputFormat.XML;
            args.LogLevel  = settings.LogLevel;
            args.LogFile   = TestPathGenerator.Generate(source, FileExtensions.LogFile);

            args.ReportFormat = OutputFormat.XML;
            args.ReportLevel  = ReportLevel.Detailed;
            args.ReportFile   = TestPathGenerator.Generate(source, FileExtensions.ReportFile);

            args.StandardOutFile   = ((settings.EnableStdOutRedirection) ? TestPathGenerator.Generate(source, FileExtensions.StdOutFile) : null);
            args.StandardErrorFile = ((settings.EnableStdErrRedirection) ? TestPathGenerator.Generate(source, FileExtensions.StdErrFile) : null);

            // Set '--catch_system_errors' to 'yes' if the test is not being debugged
            // or if this value was not overridden via configuration before-hand
            args.CatchSystemErrors = args.CatchSystemErrors.GetValueOrDefault(false) || !debugMode;

            return(args);
        }
Exemplo n.º 27
0
        public void DefaultSettings()
        {
            BoostTestAdapterSettings settings = new BoostTestAdapterSettings();

            AssertDefaultSettings(settings);
        }
Exemplo n.º 28
0
        public Strategy ParseTestBatchStrategy(string settingsXml)
        {
            BoostTestAdapterSettings settings = ParseXml(settingsXml);

            return(settings.TestBatchStrategy);
        }
Exemplo n.º 29
0
        public bool?ParseCatchSystemErrorsOption(string settingsXml)
        {
            BoostTestAdapterSettings settings = ParseXml(settingsXml);

            return(settings.CatchSystemErrors);
        }
Exemplo n.º 30
0
        public int ParsePostTestDelayOption(string settingsXml)
        {
            BoostTestAdapterSettings settings = ParseXml(settingsXml);

            return(settings.PostTestDelay);
        }