Пример #1
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);
        }
        public void TestDiscoverTestsComplex()
        {
            QmlTestRunnerMock.Setup(m => m.Execute(It.IsRegex("-functions"), It.IsAny <IDiscoveryContext>())).Returns(
                new QmlTestRunnerResult("", FunctionsComplex, 0));

            TestDiscoverer.DiscoverTests(new string[] { Path }, null, FrameworkHandleMock.Object, DiscoverySinkMock.Object);

            DiscoverySinkMock.Verify(m => m.SendTestCase(It.IsAny <TestCase>()), Times.Exactly(5));
        }
Пример #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);
        }
        public void DiscoverTests_UsingSilverlightUnitTestDll_FindsTests()
        {
            TestDiscoverer discoverer = new TestDiscoverer();

            string thisAssemblyFilePath = Assembly.GetExecutingAssembly().Location;
            string thisAssemblyPath     = Path.GetDirectoryName(thisAssemblyFilePath);
            string thisProjectBinPath   = Path.GetDirectoryName(thisAssemblyPath);
            string thisProjectPath      = Path.GetDirectoryName(thisProjectBinPath);
            string thisSolutionPath     = Path.GetDirectoryName(thisProjectPath);

            Assert.IsNotNull(thisSolutionPath);

            string silverlightUnitTestProjectPath = Path.Combine(thisSolutionPath, "SilverlightUnitTest");
            string silverlightUnitTestDllFilePath = Path.Combine(silverlightUnitTestProjectPath, "bin", ConfigurationName, "SilverlightUnitTest.dll");

            Assert.IsTrue(File.Exists(silverlightUnitTestDllFilePath), $"File doesn't exist: {silverlightUnitTestDllFilePath}");

            List <string> testAssemblies = new List <string>
            {
                silverlightUnitTestDllFilePath
            };

            Mock <IDiscoveryContext> mockDiscoveryContext = new Mock <IDiscoveryContext>();
            ConsoleMessageLogger     consoleMessageLogger = new ConsoleMessageLogger();

            Mock <ITestCaseDiscoverySink> mockTestCaseDiscoverySink = new Mock <ITestCaseDiscoverySink>();

            List <TestCase> discoveredTestCases = new List <TestCase>();

            mockTestCaseDiscoverySink.Setup(x => x.SendTestCase(It.IsAny <TestCase>())).Callback <TestCase>((testCase) =>
            {
                discoveredTestCases.Add(testCase);
            });

            discoverer.DiscoverTests(
                testAssemblies,
                mockDiscoveryContext.Object,
                consoleMessageLogger,
                mockTestCaseDiscoverySink.Object);

            List <string> expectedTestCaseDisplayNames = new List <string>
            {
                "SilverlightUnitTest.AsyncTest.EnqueueTestComplete_ShouldPass",
                "SilverlightUnitTest.AsyncTest.Assert_Fail_ShouldFail",
                "SilverlightUnitTest.AsyncTest.ReturnTask_ShouldPass",
                "SilverlightUnitTest.AsyncTest.ReturnTask_WithAssertFail_ShouldFail",
                "SilverlightUnitTest.AsyncTest.AwaitTask_ShouldPass",
                "SilverlightUnitTest.AsyncTest.AwaitTask_WithAssertFail_ShouldFail",
                "SilverlightUnitTest.UnitTest1.TestMethod1"
            };

            List <string> discoveredTestCaseNames = discoveredTestCases.Select(x => x.FullyQualifiedName).ToList();
            string        message = string.Join(Environment.NewLine, discoveredTestCaseNames);

            CollectionAssert.AreEqual(expectedTestCaseDisplayNames, discoveredTestCaseNames, message);
        }
        public void TestDiscoverTestsError()
        {
            QmlTestRunnerMock.Setup(m => m.Execute(It.IsRegex("-functions"), It.IsAny <IDiscoveryContext>())).Returns(
                new QmlTestRunnerResult("", FunctionsError, 1));

            TestDiscoverer.DiscoverTests(new string[] { Path }, null, FrameworkHandleMock.Object, DiscoverySinkMock.Object);

            DiscoverySinkMock.Verify(m => m.SendTestCase(It.IsAny <TestCase>()), Times.Never());

            FrameworkHandleMock.Verify(m => m.SendMessage(TestMessageLevel.Error, It.IsAny <string>()),
                                       Times.Once());
        }
        public void TestDiscoverTestsSimple()
        {
            QmlTestRunnerMock.Setup(m => m.Execute(It.IsRegex("-functions"), It.IsAny <IDiscoveryContext>())).Returns(
                new QmlTestRunnerResult("", FunctionsSimple, 0));

            TestDiscoverer.DiscoverTests(new string[] { Path }, null, FrameworkHandleMock.Object, DiscoverySinkMock.Object);

            DiscoverySinkMock.Verify(m => m.SendTestCase(It.Is <TestCase>(tc =>
                                                                          tc.FullyQualifiedName == "simpletest::test_simple" &&
                                                                          tc.CodeFilePath == Path &&
                                                                          tc.ExecutorUri == QmlTestExecutor.ExecutorUri &&
                                                                          tc.Source == Path
                                                                          )), Times.Once);
        }
Пример #7
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);
        }
Пример #8
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);
        }
Пример #9
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()));
        }