Esempio n. 1
0
        public void DiscoverTests(IEnumerable <string> sources, IDiscoveryContext discoveryContext, IMessageLogger logger, ITestCaseDiscoverySink discoverySink)
        {
            logger.SendMessage(TestMessageLevel.Informational, "Catch Discover in process ...");

            // Load settings from the discovery context.
            CatchAdapterSettings settings = CatchSettingsProvider.LoadSettings(discoveryContext.RunSettings);

            try
            {
                foreach (var src in sources.Where(src => settings.IncludeTestExe(src)))
                {
                    logger.SendMessage(TestMessageLevel.Informational, $"Processing catch test source: '{src}'...");

                    var testCases = CreateTestCases(src);
                    foreach (var t in testCases)
                    {
                        discoverySink.SendTestCase(t);
                        logger.SendMessage(TestMessageLevel.Informational, t.DisplayName);
                    }
                }
            }
            catch (Exception ex)
            {
                // Just log the error message.
                logger.SendMessage(TestMessageLevel.Error, ex.Message);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Runs the test of an given executable. This implies to run the discover for these sources.
        /// </summary>
        /// <param name="sources">The full qualified name of an executable to run</param>
        /// <param name="runContext">Test context</param>
        /// <param name="frameworkHandle">Test frame work handle</param>
        public void RunTests(IEnumerable <string> sources, IRunContext runContext, IFrameworkHandle frameworkHandle)
        {
            // Load settings from the context.
            var settings = CatchSettingsProvider.LoadSettings(runContext.RunSettings);

            frameworkHandle.SendMessage(TestMessageLevel.Informational, "CatchAdapter::RunTests... ");

            // Run tests in all included executables.
            foreach (var exeName in sources.Where(name => settings.IncludeTestExe(name)))
            {
                // Wrap execution in try to stop one executable's exceptions from stopping the others from being run.
                try
                {
                    frameworkHandle.SendMessage(TestMessageLevel.Informational, "RunTest of source " + exeName);
                    var tests = TestDiscoverer.CreateTestCases(exeName, runContext.SolutionDirectory);

                    RunTests(tests, runContext, frameworkHandle);
                }
                catch (Exception ex)
                {
                    frameworkHandle.SendMessage(TestMessageLevel.Error, "Exception running tests: " + ex.Message);
                    frameworkHandle.SendMessage(TestMessageLevel.Error, "Exception stack: " + ex.StackTrace);
                }
            }
        }
Esempio n. 3
0
        // Tests that filters in runsettings are obeyed.
        public void FiltersTestExecutables()
        {
            // Initialize a mock sink to keep track of the discovered tests.
            MockTestCaseDiscoverySink testSink = new MockTestCaseDiscoverySink();

            // Configure a mock context.
            var context  = new MockDiscoveryContext();
            var provider = new CatchSettingsProvider();

            provider.Settings = new CatchAdapterSettings();
            provider.Settings.TestExeInclude.Add(@"ReferenceCatchProject\.exe");
            context.MockSettings.Provider = provider;

            // Discover tests from the reference project and from anon-existent exe.
            // The non-existent exe should get filtered out and cause no trouble.
            TestDiscoverer discoverer = new TestDiscoverer();
            List <string>  exeList    = new List <string>();

            exeList.AddRange(Common.ReferenceExeList);
            exeList.Add("nonsense.exe");
            discoverer.DiscoverTests(Common.ReferenceExeList,
                                     context,
                                     new MockMessageLogger(),
                                     testSink);

            // There is a known number of test cases in the reference project.
            Assert.AreEqual(Common.ReferenceTestCount, testSink.Tests.Count);

            // Clear the sink.
            testSink = new MockTestCaseDiscoverySink();

            // Filter all exes.
            provider.Settings.TestExeInclude.Clear();
            provider.Settings.TestExeInclude.Add("laksjdlkjalsdjasljd");

            // Discover again.
            discoverer.DiscoverTests(Common.ReferenceExeList,
                                     context,
                                     new MockMessageLogger(),
                                     testSink);

            // There should be no tests, as nothing matches the filter.
            Assert.AreEqual(testSink.Tests.Count, 0);
        }