public void GracefullyHandleDuplicateScenarioNamesInASource()
        {
            var testCaseDiscoverySink = new MockTestCaseDiscoverySink();

            new TestDiscoverer().DiscoverTests(
                new[]
            {
                "GherkinSpec.TestAdapter.UnitTests.dll"
            },
                null,
                new NullMessageLogger(),
                testCaseDiscoverySink);

            Assert.AreEqual(
                1,
                testCaseDiscoverySink.DiscoveredTests.Count(
                    t => t.FullyQualifiedName == "Duplicate scenario" &&
                    t.DisplayName == "Duplicate scenario"));

            Assert.AreEqual(
                1,
                testCaseDiscoverySink.DiscoveredTests.Count(
                    t => t.FullyQualifiedName == "Duplicate scenario (2)" &&
                    t.DisplayName == "Duplicate scenario (2)"));

            Assert.AreEqual(
                1,
                testCaseDiscoverySink.DiscoveredTests.Count(
                    t => t.FullyQualifiedName == "Duplicate scenario (3)" &&
                    t.DisplayName == "Duplicate scenario (3)"));
        }
Exemple #2
0
        public void TestTagsToTraits()
        {
            // Initialize a mock sink to keep track of the discovered tests.
            MockTestCaseDiscoverySink testSink = new MockTestCaseDiscoverySink();

            // Discover tests from the reference project.
            TestDiscoverer discoverer = new TestDiscoverer();

            discoverer.DiscoverTests(Common.ReferenceExeList,
                                     new MockDiscoveryContext(),
                                     new MockMessageLogger(),
                                     testSink);

            // Get the test with tags.
            TestCase tagsTest = testSink.Tests.Where(test => test.DisplayName == "With tags").First();

            // The tags should be present in the test as traits.
            string traits = tagsTest.Traits
                            .Select(trait => trait.Name)
                            .Aggregate("", (acc, add) => acc + "," + add);

            Assert.AreEqual(2, tagsTest.Traits.Count());
            Assert.IsTrue(tagsTest.Traits.Any(trait => trait.Name == "tag"), traits);
            Assert.IsTrue(tagsTest.Traits.Any(trait => trait.Name == "neat"), traits);
        }
Exemple #3
0
        public void DiscoversAllTests()
        {
            // Initialize a mock sink to keep track of the discovered tests.
            MockTestCaseDiscoverySink testSink = new MockTestCaseDiscoverySink();

            // Discover tests from the reference project.
            TestDiscoverer discoverer = new TestDiscoverer();

            discoverer.DiscoverTests(Common.ReferenceExeList,
                                     new MockDiscoveryContext(),
                                     new MockMessageLogger(),
                                     testSink);

            // There is a known number of test cases in the reference project.
            Assert.AreEqual(Common.ReferenceTestCount, testSink.Tests.Count);
        }
Exemple #4
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);
        }
Exemple #5
0
        public void DiscoversNoTests()
        {
            // Initialize a mock sink to keep track of the discovered tests.
            MockTestCaseDiscoverySink testSink = new MockTestCaseDiscoverySink();

            TestDiscoverer discoverer = new TestDiscoverer();
            var            cd         = System.IO.Directory.GetCurrentDirectory();

            // Unfortunately it doesn't get copied with the DeployItemAttribute, no idea why.
            System.IO.File.WriteAllText(@"nonecatchexe.cmd", @"@echo Non Catch Output line");
            // Returns an unexpected first line.
            discoverer.DiscoverTests(new List <String>()
            {
                @"nonecatchexe.cmd"
            },
                                     new MockDiscoveryContext(),
                                     new MockMessageLogger(),
                                     testSink);

            // Zero test cases should be registered.
            Assert.AreEqual(0, testSink.Tests.Count);
        }
Exemple #6
0
        public void TestCaseLinesCorrect()
        {
            // Initialize a mock sink to keep track of the discovered tests.
            MockTestCaseDiscoverySink testSink = new MockTestCaseDiscoverySink();

            // Discover tests from the reference project.
            TestDiscoverer discoverer = new TestDiscoverer();

            discoverer.DiscoverTests(Common.ReferenceExeList,
                                     new MockDiscoveryContext(),
                                     new MockMessageLogger(),
                                     testSink);

            // The reference project test cases are on these lines.
            var linesOfCases = new Dictionary <string, int>();

            linesOfCases.Add("No tags", 6);
            linesOfCases.Add("With tags", 16);
            linesOfCases.Add("Has failure", 24);

            foreach (var test in testSink.Tests)
            {
                // Process only tests we have hard coded here.
                if (linesOfCases.ContainsKey(test.FullyQualifiedName))
                {
                    // Check that the line number is correct.
                    Assert.AreEqual(linesOfCases[test.FullyQualifiedName], test.LineNumber, test.FullyQualifiedName);

                    // Remove the case so we can check all were handled.
                    linesOfCases.Remove(test.FullyQualifiedName);
                }
            }

            // Make sure all the cases we wanted got checked.
            Assert.AreEqual(linesOfCases.Count, 0, String.Format("Unhandled cases: {0}", linesOfCases.ToString()));
        }