コード例 #1
0
        public void IsGoogleTestExecutable_WithUnparsableRegexFromOptions_ProducesErrorMessage()
        {
            bool result = new GoogleTestDiscoverer(TestEnvironment).IsGoogleTestExecutable("my.exe", "d[ddd[");

            result.Should().BeFalse();
            MockLogger.Verify(l => l.LogError(It.Is<string>(s => s.Contains("'d[ddd['"))), Times.Exactly(1));
        }
コード例 #2
0
 private void AssertIsGoogleTestExecutable(string executable, bool isGoogleTestExecutable, string regex = "")
 {
     GoogleTestDiscoverer.IsGoogleTestExecutable(executable, regex, TestEnvironment.Logger)
     .Should()
     .Be(isGoogleTestExecutable);
 }
コード例 #3
0
        public void GetTestsFromExecutable_WithoutPathExtension_ProducesWarning()
        {
            var discoverer = new GoogleTestDiscoverer(TestEnvironment);
            IList<TestCase> testCases = discoverer.GetTestsFromExecutable(TestResources.PathExtensionTestsExe);

            testCases.Count.Should().Be(0);
            MockLogger.Verify(l => l.LogWarning(It.Is<string>(s => s.StartsWith("Could not list test cases of executable"))));
        }
コード例 #4
0
        public void GetTestsFromExecutable_WithPathExtension_FindsTestsWithLocation()
        {
            MockOptions.Setup(o => o.PathExtension).Returns(SettingsWrapper.ExecutableDirPlaceholder + @"\..\lib");

            var discoverer = new GoogleTestDiscoverer(TestEnvironment);
            IList<TestCase> testCases = discoverer.GetTestsFromExecutable(TestResources.PathExtensionTestsExe);
            testCases.Count.Should().Be(TestResources.NrOfPathExtensionTests);
        }
コード例 #5
0
        // ReSharper disable once UnusedParameter.Local
        private void AssertFindsParameterizedTest(string fullyQualifiedName, Regex displayNameRegex)
        {
            File.Exists(TestResources.SampleTests)
                .Should()
                .BeTrue("Build SampleTests in Debug mode before executing this test");

            var discoverer = new GoogleTestDiscoverer(TestEnvironment);
            IList<TestCase> tests = discoverer.GetTestsFromExecutable(TestResources.SampleTests);

            TestCase testCase = tests.Single(t => t.FullyQualifiedName == fullyQualifiedName);
            displayNameRegex.IsMatch(testCase.DisplayName).Should().BeTrue();
        }
コード例 #6
0
        private void FindExternallyLinkedTests(string location)
        {
            var discoverer = new GoogleTestDiscoverer(TestEnvironment);
            IList<TestCase> testCases = discoverer.GetTestsFromExecutable(location);

            testCases.Count.Should().Be(2);

            testCases[0].DisplayName.Should().Be("BarTest.MethodBarDoesAbc");
            testCases[0].CodeFilePath.Should().Be(@"c:\prod\gtest-1.7.0\externalgoogletestlibrary\externalgoogletestlibrarytests.cpp");
            testCases[0].LineNumber.Should().Be(36);

            testCases[1].DisplayName.Should().Be("BarTest.DoesXyz");
            testCases[1].CodeFilePath.Should().Be(@"c:\prod\gtest-1.7.0\externalgoogletestlibrary\externalgoogletestlibrarytests.cpp");
            testCases[1].LineNumber.Should().Be(44);
        }
コード例 #7
0
        private void FindSampleTests(string location)
        {
            var discoverer = new GoogleTestDiscoverer(TestEnvironment);
            IList<TestCase> testCases = discoverer.GetTestsFromExecutable(location);

            testCases.Count.Should().Be(TestResources.NrOfSampleTests);

            TestCase testCase =
               testCases.Single(tc => tc.FullyQualifiedName == "Arr/TypeParameterizedTests/1.CanDefeatMath");

            testCase.DisplayName.Should().Be("Arr/TypeParameterizedTests/1.CanDefeatMath<MyStrangeArray>");
            testCase.CodeFilePath.Should().EndWith(@"sampletests\tests\typeparameterizedtests.cpp");
            testCase.LineNumber.Should().Be(53);
        }
コード例 #8
0
        public void GetTestsFromExecutable_LoadTests_AreFoundInReasonableTime()
        {
            var stopwatch = Stopwatch.StartNew();
            var discoverer = new GoogleTestDiscoverer(TestEnvironment);
            IList<TestCase> testCases = discoverer.GetTestsFromExecutable(TestResources.LoadTests);
            stopwatch.Stop();
            var actualDuration = stopwatch.Elapsed;

            int testParsingDurationInMs = CiSupport.GetWeightedDuration(0.5 * testCases.Count); // .5ms per test (discovery and processing)
            int overheadInMs = CiSupport.GetWeightedDuration(1000); // pretty much arbitrary - let's see...
            var maxDuration = TimeSpan.FromMilliseconds(testParsingDurationInMs + overheadInMs);

            actualDuration.Should().BeLessThan(maxDuration);
        }
コード例 #9
0
        public void GetTestsFromExecutable_DoNotParseSymbolInformation_DiaIsNotInvoked()
        {
            var mockFactory = new Mock<IDiaResolverFactory>();
            MockOptions.Setup(o => o.ParseSymbolInformation).Returns(false);

            IList<TestCase> testCases = new GoogleTestDiscoverer(TestEnvironment, mockFactory.Object)
                .GetTestsFromExecutable(TestResources.SampleTests);

            mockFactory.Verify(f => f.Create(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<ILogger>(), false), Times.Never);
            testCases.Count.Should().Be(TestResources.NrOfSampleTests);
            foreach (TestCase testCase in testCases)
            {
                testCase.CodeFilePath.Should().Be("");
                testCase.LineNumber.Should().Be(0);
                testCase.Source.Should().Be(TestResources.SampleTests);
                testCase.DisplayName.Should().NotBeNullOrEmpty();
                testCase.FullyQualifiedName.Should().NotBeNullOrEmpty();
            }
        }
        private void AssertFindsTestWithTraits(string displayName, Trait[] traits)
        {
            File.Exists(SampleTestToUse)
                .Should()
                .BeTrue("Build SampleTests in Debug and Release mode before executing this test");

            GoogleTestDiscoverer discoverer = new GoogleTestDiscoverer(TestEnvironment);
            List<TestCase> tests = discoverer.GetTestsFromExecutable(SampleTestToUse).ToList();

            TestCase testCase = tests.Find(tc => tc.Traits.Count == traits.Length && tc.DisplayName.StartsWith(displayName));
            testCase.Should().NotBeNull($"Test not found: {displayName}, {traits.Length}");

            foreach (Trait trait in traits)
            {
                Trait foundTrait = testCase.Traits.FirstOrDefault(T => trait.Name == T.Name && trait.Value == T.Value);
                foundTrait.Should().NotBeNull("Didn't find trait: (" + trait.Name + ", " + trait.Value + ")");
            }
        }