コード例 #1
0
        public void MutationTestExecutor_TimeoutShouldBePassedToProcessTimeout()
        {
            var testRunnerMock = new Mock <ITestRunner>(MockBehavior.Strict);
            var mutant         = new Mutant {
                Id = 1
            };

            testRunnerMock.Setup(x => x.RunAll(It.IsAny <int>(), mutant)).Returns(new TestRunResult {
                Success = false
            });

            var target = new MutationTestExecutor(testRunnerMock.Object);

            target.Test(mutant, 1999);

            mutant.ResultStatus.ShouldBe(MutantStatus.Killed);
            testRunnerMock.Verify(x => x.RunAll(1999, mutant), Times.Once);
        }
コード例 #2
0
        public void MutationTestExecutor_FailedTestShouldBeKilled()
        {
            var testRunnerMock = new Mock <ITestRunner>(MockBehavior.Strict);
            var mutant         = new Mutant {
                Id = 1, MustRunAgainstAllTests = true
            };

            testRunnerMock.Setup(x => x.RunAll(It.IsAny <int>(), mutant, null)).Returns(new TestRunResult(false));

            var target = new MutationTestExecutor(testRunnerMock.Object);

            target.Test(new List <Mutant> {
                mutant
            }, 0, null);

            mutant.ResultStatus.ShouldBe(MutantStatus.Killed);
            testRunnerMock.Verify(x => x.RunAll(It.IsAny <int>(), mutant, null), Times.Once);
        }
コード例 #3
0
        public void MutationTestExecutor_NoFailedTestShouldBeSurvived()
        {
            var testRunnerMock = new Mock <ITestRunner>(MockBehavior.Strict);
            var mutant         = new Mutant {
                Id = 1
            };

            testRunnerMock.Setup(x => x.RunAll(It.IsAny <int>(), mutant)).Returns(new TestRunResult {
                Success = true
            });

            var target = new MutationTestExecutor(testRunnerMock.Object);

            target.Test(mutant, 0);

            mutant.ResultStatus.ShouldBe(MutantStatus.Survived);
            testRunnerMock.Verify(x => x.RunAll(It.IsAny <int>(), mutant), Times.Once);
        }
コード例 #4
0
        public void MutationTestExecutor_FailedTestShouldBeKilled()
        {
            var testRunnerMock = new Mock <ITestRunner>(MockBehavior.Strict);
            var mutant         = new Mutant {
                Id = 1, CoveringTests = TestsGuidList.EveryTest()
            };

            testRunnerMock.Setup(x => x.TestMultipleMutants(null, It.IsAny <IReadOnlyList <Mutant> >(), null)).Returns(new TestRunResult(false));

            var target = new MutationTestExecutor(testRunnerMock.Object);

            target.Test(new List <Mutant> {
                mutant
            }, null, null);

            mutant.ResultStatus.ShouldBe(MutantStatus.Killed);
            testRunnerMock.Verify(x => x.TestMultipleMutants(null, It.IsAny <IReadOnlyList <Mutant> >(), null), Times.Once);
        }
コード例 #5
0
        public void MutationTestExecutor_NoFailedTestShouldBeSurvived()
        {
            var testRunnerMock = new Mock <ITestRunner>(MockBehavior.Strict);
            var mutant         = new Mutant {
                Id = 1
            };

            testRunnerMock.Setup(x => x.TestMultipleMutants(It.IsAny <ITimeoutValueCalculator>(), It.IsAny <IReadOnlyList <Mutant> >(), null)).Returns(new TestRunResult(true));

            var target = new MutationTestExecutor(testRunnerMock.Object);

            target.Test(new List <Mutant> {
                mutant
            }, null, null);

            mutant.ResultStatus.ShouldBe(MutantStatus.Survived);
            testRunnerMock.Verify(x => x.TestMultipleMutants(It.IsAny <ITimeoutValueCalculator>(), It.IsAny <IReadOnlyList <Mutant> >(), null), Times.Once);
        }
コード例 #6
0
        public void MutationTestExecutor_TimeoutShouldBePassedToProcessTimeout()
        {
            var testRunnerMock = new Mock <ITestRunner>(MockBehavior.Strict);
            var mutant         = new Mutant {
                Id = 1, MustRunAgainstAllTests = true
            };

            testRunnerMock.Setup(x => x.RunAll(It.IsAny <int>(), mutant, null)).
            Returns(TestRunResult.TimedOut(TestListDescription.NoTest(), TestListDescription.NoTest(), TestListDescription.EveryTest(), ""));

            var target = new MutationTestExecutor(testRunnerMock.Object);

            target.Test(new List <Mutant> {
                mutant
            }, 1999, null);

            mutant.ResultStatus.ShouldBe(MutantStatus.Timeout);
            testRunnerMock.Verify(x => x.RunAll(1999, mutant, null), Times.Once);
        }
コード例 #7
0
        public void MutationTestExecutor_TimeoutShouldBePassedToProcessTimeout()
        {
            var testRunnerMock = new Mock <ITestRunner>(MockBehavior.Strict);
            var mutant         = new Mutant {
                Id = 1, CoveringTests = TestsGuidList.EveryTest()
            };

            testRunnerMock.Setup(x => x.TestMultipleMutants(It.IsAny <ITimeoutValueCalculator>(), It.IsAny <IReadOnlyList <Mutant> >(), null)).
            Returns(TestRunResult.TimedOut(TestsGuidList.NoTest(), TestsGuidList.NoTest(), TestsGuidList.EveryTest(), "", TimeSpan.Zero));

            var target = new MutationTestExecutor(testRunnerMock.Object);

            var timeoutValueCalculator = new TimeoutValueCalculator(500);

            target.Test(new List <Mutant> {
                mutant
            }, timeoutValueCalculator, null);

            mutant.ResultStatus.ShouldBe(MutantStatus.Timeout);
            testRunnerMock.Verify(x => x.TestMultipleMutants(timeoutValueCalculator, It.IsAny <IReadOnlyList <Mutant> >(), null), Times.Once);
        }
コード例 #8
0
        public void MutationTestExecutor_FailedTestShouldBeKilled()
        {
            var testRunnerMock = new Mock <ITestRunner>(MockBehavior.Strict);

            testRunnerMock.Setup(x => x.SetActiveMutation(It.IsAny <int>()));
            testRunnerMock.Setup(x => x.RunAll(It.IsAny <int>())).Returns(new TestRunResult()
            {
                Success = false
            });

            var mutant = new Mutant()
            {
                Id = 1
            };
            var target = new MutationTestExecutor(testRunnerMock.Object, 0);

            target.Test(mutant);

            mutant.ResultStatus.ShouldBe(MutantStatus.Killed);
            testRunnerMock.Verify(x => x.SetActiveMutation(1), Times.Once);
            testRunnerMock.Verify(x => x.RunAll(It.IsAny <int>()), Times.Once);
        }
コード例 #9
0
        public void ShouldHandleTestFailingAtInit()
        {
            var scenario = new FullRunScenario();
            var basePath = Path.Combine(FilesystemRoot, "ExampleProject.Test");

            scenario.CreateMutants(1, 2);

            var folder = new CsharpFolderComposite();

            folder.Add(new CsharpFileLeaf()
            {
                SourceCode = SourceFile,
                Mutants    = scenario.GetMutants()
            });
            scenario.CreateTests(1, 2, 3);

            // mutant 1 is covered by both tests
            scenario.DeclareCoverageForMutant(1);
            // mutant 2 is covered only by test 1
            scenario.DeclareCoverageForMutant(2, 1, 3);
            scenario.DeclareTestsFailingAtInit(1);
            // test 1 succeeds, test 2 fails
            scenario.DeclareTestsFailingWhenTestingMutant(1, 1, 2);
            scenario.DeclareTestsFailingWhenTestingMutant(2, 1);
            var runnerMock = scenario.GetTestRunnerMock();

            // setup coverage
            var executor = new MutationTestExecutor(runnerMock.Object);

            var input = new MutationTestInput
            {
                ProjectInfo = new ProjectInfo(new MockFileSystem())
                {
                    ProjectUnderTestAnalyzerResult = TestHelper.SetupProjectAnalyzerResult(properties: new Dictionary <string, string>()
                    {
                        { "TargetDir", "/bin/Debug/netcoreapp2.1" },
                        { "TargetFileName", "TestName.dll" },
                        { "Language", "C#" }
                    }).Object,
                    ProjectContents = folder
                },
                AssemblyReferences = _assemblies,
                InitialTestRun     = new InitialTestRun(scenario.GetInitialRunResult(), new TimeoutValueCalculator(500))
            };

            var mutantFilterMock = new Mock <IMutantFilter>(MockBehavior.Loose);

            var options = new StrykerOptions
            {
                BasePath         = basePath,
                Concurrency      = 1,
                OptimizationMode = OptimizationModes.CoverageBasedTest
            };

            var target = new MutationTestProcess(input,
                                                 null,
                                                 executor,
                                                 mutantFilter: mutantFilterMock.Object,
                                                 options: options);

            // test mutants
            target.GetCoverage();

            target.Test(input.ProjectInfo.ProjectContents.Mutants);
            // first mutant should be killed by test 2
            scenario.GetMutantStatus(1).ShouldBe(MutantStatus.Killed);
            // other mutant survives
            scenario.GetMutantStatus(2).ShouldBe(MutantStatus.Survived);
        }
コード例 #10
0
        public void ShouldCallExecutorForEveryCoveredMutant()
        {
            var scenario = new FullRunScenario();

            scenario.CreateMutants(1, 2);
            // we need at least one test
            scenario.CreateTest(1);
            // and we need to declare that the mutant is covered
            scenario.DeclareCoverageForMutant(1);
            var basePath = Path.Combine(FilesystemRoot, "ExampleProject.Test");

            var folder = new CsharpFolderComposite();

            folder.Add(new CsharpFileLeaf()
            {
                SourceCode = SourceFile,
                Mutants    = scenario.GetMutants()
            });

            var input = new MutationTestInput()
            {
                ProjectInfo = new ProjectInfo(new MockFileSystem())
                {
                    ProjectUnderTestAnalyzerResult = TestHelper.SetupProjectAnalyzerResult(properties: new Dictionary <string, string>()
                    {
                        { "TargetDir", "/bin/Debug/netcoreapp2.1" },
                        { "TargetFileName", "TestName.dll" },
                        { "Language", "C#" }
                    }).Object
                    ,
                    ProjectContents = folder
                },
                AssemblyReferences = _assemblies,
                InitialTestRun     = new InitialTestRun(scenario.GetInitialRunResult(), new TimeoutValueCalculator(500))
            };
            var reporterMock = new Mock <IReporter>(MockBehavior.Strict);

            reporterMock.Setup(x => x.OnMutantTested(It.IsAny <Mutant>()));

            var mutationExecutor = new MutationTestExecutor(scenario.GetTestRunnerMock().Object);

            var mutantFilterMock = new Mock <IMutantFilter>(MockBehavior.Loose);

            var options = new StrykerOptions()
            {
                BasePath         = basePath,
                Concurrency      = 1,
                OptimizationMode = OptimizationModes.CoverageBasedTest
            };
            var target = new MutationTestProcess(input,
                                                 reporterMock.Object,
                                                 mutationExecutor,
                                                 mutantFilter: mutantFilterMock.Object,
                                                 options: options);

            target.GetCoverage();
            target.Test(scenario.GetCoveredMutants());

            scenario.GetMutantStatus(1).ShouldBe(MutantStatus.Survived);
            scenario.GetMutantStatus(2).ShouldBe(MutantStatus.NoCoverage);
        }