Пример #1
0
        public void MutationTestProcess_ShouldCallExecutorForEveryMutant()
        {
            var mutant = new Mutant()
            {
                Id = 1
            };
            string basePath = Path.Combine(_filesystemRoot, "ExampleProject.Test");
            var    input    = new MutationTestInput()
            {
                ProjectInfo = new Core.Initialisation.ProjectInfo()
                {
                    TestProjectPath = basePath,
                    ProjectContents = new FolderComposite()
                    {
                        Name     = "ProjectRoot",
                        Children = new Collection <ProjectComponent>()
                        {
                            new FileLeaf()
                            {
                                Name    = "SomeFile.cs",
                                Mutants = new Collection <Mutant>()
                                {
                                    mutant
                                }
                            }
                        }
                    },
                    ProjectUnderTestAssemblyName = "ExampleProject",
                    ProjectUnderTestPath         = Path.Combine(_filesystemRoot, "ExampleProject"),
                    TargetFramework = "netcoreapp2.0",
                },
                AssemblyReferences = new ReferenceProvider().GetReferencedAssemblies()
            };
            var reporterMock = new Mock <IReporter>(MockBehavior.Strict);

            reporterMock.Setup(x => x.OnMutantTested(It.IsAny <Mutant>()));
            reporterMock.Setup(x => x.OnAllMutantsTested(It.IsAny <ProjectComponent>()));
            reporterMock.Setup(x => x.OnStartMutantTestRun(It.IsAny <IList <Mutant> >()));

            var executorMock = new Mock <IMutationTestExecutor>(MockBehavior.Strict);

            executorMock.Setup(x => x.Test(It.IsAny <Mutant>()));

            var options = new StrykerOptions(basePath: Path.Combine(_filesystemRoot, "test"));

            var target = new MutationTestProcess(input,
                                                 reporterMock.Object,
                                                 Enumerable.Empty <MutatorType>(),
                                                 executorMock.Object,
                                                 null,
                                                 null,
                                                 null);

            target.Test(options);

            executorMock.Verify(x => x.Test(mutant), Times.Once);
            reporterMock.Verify(x => x.OnStartMutantTestRun(It.Is <IList <Mutant> >(y => y.Count == 1)), Times.Once);
            reporterMock.Verify(x => x.OnMutantTested(mutant), Times.Once);
            reporterMock.Verify(x => x.OnAllMutantsTested(It.IsAny <ProjectComponent>()), Times.Once);
        }
Пример #2
0
        public void ShouldNotTest_WhenAllMutationsWereSkipped()
        {
            var mutant = new Mutant()
            {
                Id = 1, ResultStatus = MutantStatus.Ignored
            };
            string basePath = Path.Combine(FilesystemRoot, "ExampleProject.Test");
            var    input    = new MutationTestInput()
            {
                ProjectInfo = new ProjectInfo()
                {
                    ProjectContents = new FolderComposite()
                    {
                        Name     = "ProjectRoot",
                        Children = new Collection <ProjectComponent>()
                        {
                            new FileLeaf()
                            {
                                Name    = "SomeFile.cs",
                                Mutants = new Collection <Mutant>()
                                {
                                    mutant
                                }
                            }
                        }
                    },
                },
                AssemblyReferences = _assemblies
            };
            var reporterMock = new Mock <IReporter>(MockBehavior.Strict);

            reporterMock.Setup(x => x.OnMutantTested(It.IsAny <Mutant>()));
            reporterMock.Setup(x => x.OnAllMutantsTested(It.IsAny <ProjectComponent>()));
            reporterMock.Setup(x => x.OnStartMutantTestRun(It.IsAny <IList <Mutant> >(), It.IsAny <IEnumerable <TestDescription> >()));

            var runnerMock = new Mock <ITestRunner>();

            runnerMock.Setup(x => x.DiscoverNumberOfTests()).Returns(1);
            var executorMock = new Mock <IMutationTestExecutor>(MockBehavior.Strict);

            executorMock.SetupGet(x => x.TestRunner).Returns(runnerMock.Object);
            executorMock.Setup(x => x.Test(It.IsAny <IList <Mutant> >(), It.IsAny <int>(), It.IsAny <TestUpdateHandler>()));

            var options = new StrykerOptions(fileSystem: new MockFileSystem(), basePath: basePath);

            var target = new MutationTestProcess(input,
                                                 reporterMock.Object,
                                                 executorMock.Object,
                                                 options: options);

            var testResult = target.Test(options);

            executorMock.Verify(x => x.Test(new List <Mutant> {
                mutant
            }, It.IsAny <int>(), It.IsAny <TestUpdateHandler>()), Times.Never);
            reporterMock.Verify(x => x.OnStartMutantTestRun(It.IsAny <IList <Mutant> >(), It.IsAny <IEnumerable <TestDescription> >()), Times.Never);
            reporterMock.Verify(x => x.OnMutantTested(mutant), Times.Never);
            reporterMock.Verify(x => x.OnAllMutantsTested(It.IsAny <ProjectComponent>()), Times.Once);
            testResult.MutationScore.ShouldBe(double.NaN);
        }
Пример #3
0
        /// <summary>
        /// Starts a mutation test run
        /// </summary>
        /// <exception cref="StrykerInputException">For managed exceptions</exception>
        /// <param name="options">The user options</param>
        public StrykerRunResult RunMutationTest(StrykerOptions options)
        {
            // start stopwatch
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            // Create output dir with gitignore
            FileSystem.Directory.CreateDirectory(options.OutputPath);
            FileSystem.File.Create(Path.Combine(options.OutputPath, ".gitignore")).Close();
            using (var file = FileSystem.File.CreateText(Path.Combine(options.OutputPath, ".gitignore")))
            {
                file.WriteLine("*");
            }

            // setup logging
            ApplicationLogging.ConfigureLogger(options.LogOptions);
            var logger = ApplicationLogging.LoggerFactory.CreateLogger <StrykerRunner>();

            logger.LogDebug("Stryker started with options: {0}",
                            JsonConvert.SerializeObject(options, new StringEnumConverter()));

            try
            {
                // initialize
                Reporter = ReporterFactory.Create(options);
                InitialisationProcess = InitialisationProcess ?? new InitialisationProcess();
                Input = InitialisationProcess.Initialize(options);

                MutationTestProcess = MutationTestProcess ?? new MutationTestProcess(
                    mutationTestInput: Input,
                    reporter: Reporter,
                    mutationTestExecutor: new MutationTestExecutor(Input.TestRunner));

                // initial test
                Input.TimeoutMs = InitialisationProcess.InitialTest(options);

                // mutate
                MutationTestProcess.Mutate(options);

                // coverage
                var coverage = InitialisationProcess.GetCoverage(options);

                MutationTestProcess.Optimize(coverage);

                // test mutations and return results
                return(MutationTestProcess.Test(options));
            }
            catch (Exception ex) when(!(ex is StrykerInputException))
            {
                logger.LogError(ex, "An error occurred during the mutation test run ");
                throw;
            }
            finally
            {
                // log duration
                stopwatch.Stop();
                logger.LogInformation("Time Elapsed {0}", stopwatch.Elapsed);
            }
        }
Пример #4
0
        public void ShouldNotTest_WhenThereAreNoTestableMutations()
        {
            string basePath = Path.Combine(FilesystemRoot, "ExampleProject.Test");

            var folder = new CsharpFolderComposite()
            {
                Name = "ProjectRoot"
            };

            folder.Add(new CsharpFileLeaf()
            {
                Name    = "SomeFile.cs",
                Mutants = new Collection <Mutant>()
                {
                }
            });

            var projectUnderTest = TestHelper.SetupProjectAnalyzerResult(
                properties: new Dictionary <string, string>()
            {
                { "Language", "F#" }
            }).Object;
            var input = new MutationTestInput()
            {
                ProjectInfo = new ProjectInfo()
                {
                    ProjectContents = folder,
                    ProjectUnderTestAnalyzerResult = projectUnderTest
                },
                AssemblyReferences = _assemblies
            };
            var reporterMock = new Mock <IReporter>(MockBehavior.Strict);

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

            var runnerMock = new Mock <ITestRunner>();

            runnerMock.Setup(x => x.DiscoverNumberOfTests()).Returns(1);
            var executorMock = new Mock <IMutationTestExecutor>(MockBehavior.Strict);

            executorMock.SetupGet(x => x.TestRunner).Returns(runnerMock.Object);
            executorMock.Setup(x => x.Test(It.IsAny <IList <Mutant> >(), It.IsAny <int>(), It.IsAny <TestUpdateHandler>()));

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

            var options = new StrykerOptions(fileSystem: new MockFileSystem(), basePath: basePath);

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

            var testResult = target.Test(folder.Mutants);

            executorMock.Verify(x => x.Test(It.IsAny <IList <Mutant> >(), It.IsAny <int>(), It.IsAny <TestUpdateHandler>()), Times.Never);
            reporterMock.Verify(x => x.OnMutantTested(It.IsAny <Mutant>()), Times.Never);
            testResult.MutationScore.ShouldBe(double.NaN);
        }
Пример #5
0
        public void MutationTestProcess_ShouldNotTest_WhenThereAreNoTestableMutations()
        {
            var mutant = new Mutant()
            {
                Id = 1, ResultStatus = MutantStatus.Skipped
            };
            var mutant2 = new Mutant()
            {
                Id = 2, ResultStatus = MutantStatus.CompileError
            };
            string basePath = Path.Combine(FilesystemRoot, "ExampleProject.Test");
            var    input    = new MutationTestInput()
            {
                ProjectInfo = new ProjectInfo()
                {
                    ProjectContents = new FolderComposite()
                    {
                        Name     = "ProjectRoot",
                        Children = new Collection <ProjectComponent>()
                        {
                            new FileLeaf()
                            {
                                Name    = "SomeFile.cs",
                                Mutants = new Collection <Mutant>()
                                {
                                    mutant, mutant2
                                }
                            }
                        }
                    },
                },
                AssemblyReferences = _assemblies
            };
            var reporterMock = new Mock <IReporter>(MockBehavior.Strict);

            reporterMock.Setup(x => x.OnMutantTested(It.IsAny <Mutant>()));
            reporterMock.Setup(x => x.OnAllMutantsTested(It.IsAny <ProjectComponent>()));
            reporterMock.Setup(x => x.OnStartMutantTestRun(It.IsAny <IList <Mutant> >()));

            var executorMock = new Mock <IMutationTestExecutor>(MockBehavior.Strict);

            executorMock.SetupGet(x => x.TestRunner).Returns(Mock.Of <ITestRunner>());
            executorMock.Setup(x => x.Test(It.IsAny <Mutant>(), It.IsAny <int>()));

            var options = new StrykerOptions(fileSystem: new MockFileSystem(), basePath: basePath);

            var target = new MutationTestProcess(input,
                                                 reporterMock.Object,
                                                 executorMock.Object);

            var testResult = target.Test(options);

            executorMock.Verify(x => x.Test(It.IsAny <Mutant>(), It.IsAny <int>()), Times.Never);
            reporterMock.Verify(x => x.OnStartMutantTestRun(It.IsAny <IList <Mutant> >()), Times.Never);
            reporterMock.Verify(x => x.OnMutantTested(It.IsAny <Mutant>()), Times.Never);
            reporterMock.Verify(x => x.OnAllMutantsTested(It.IsAny <ProjectComponent>()), Times.Never);
            testResult.MutationScore.ShouldBeNull();
        }
Пример #6
0
        public void ShouldNotTest_WhenThereAreNoMutationsAtAll()
        {
            string basePath = Path.Combine(FilesystemRoot, "ExampleProject.Test");
            var    scenario = new FullRunScenario();
            var    folder   = new CsharpFolderComposite();

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

            var projectUnderTest = TestHelper.SetupProjectAnalyzerResult(
                properties: new Dictionary <string, string>()
            {
                { "Language", "C#" }
            }).Object;
            var input = new MutationTestInput()
            {
                ProjectInfo = new ProjectInfo(new MockFileSystem())
                {
                    ProjectContents = folder,
                    ProjectUnderTestAnalyzerResult = projectUnderTest
                },
                AssemblyReferences = _assemblies
            };

            var executorMock = new Mock <IMutationTestExecutor>(MockBehavior.Strict);

            executorMock.SetupGet(x => x.TestRunner).Returns(scenario.GetTestRunnerMock().Object);
            executorMock.Setup(x => x.Test(It.IsAny <IList <Mutant> >(), It.IsAny <ITimeoutValueCalculator>(), It.IsAny <TestUpdateHandler>()));

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

            var options = new StrykerOptions()
            {
                BasePath = basePath
            };

            var reporterMock = new Mock <IReporter>(MockBehavior.Strict);

            reporterMock.Setup(x => x.OnMutantTested(It.IsAny <Mutant>()));
            var target = new MutationTestProcess(input,
                                                 reporterMock.Object,
                                                 executorMock.Object,
                                                 mutantFilter: mutantFilterMock.Object,
                                                 options: options);

            var testResult = target.Test(input.ProjectInfo.ProjectContents.Mutants);

            executorMock.Verify(x => x.Test(It.IsAny <IList <Mutant> >(), It.IsAny <ITimeoutValueCalculator>(), It.IsAny <TestUpdateHandler>()), Times.Never);
            reporterMock.Verify(x => x.OnStartMutantTestRun(It.IsAny <IList <Mutant> >()), Times.Never);
            reporterMock.Verify(x => x.OnMutantTested(It.IsAny <Mutant>()), Times.Never);
            testResult.MutationScore.ShouldBe(double.NaN);
        }
        public void ShouldNotTest_WhenThereAreNoMutationsAtAll()
        {
            string basePath = Path.Combine(FilesystemRoot, "ExampleProject.Test");

            var folder = new FolderComposite()
            {
                Name = "ProjectRoot"
            };

            folder.Add(new FileLeaf()
            {
                Name    = "SomeFile.cs",
                Mutants = new Collection <Mutant>()
                {
                }
            });

            var input = new MutationTestInput()
            {
                ProjectInfo = new ProjectInfo()
                {
                    ProjectContents = folder
                },
                AssemblyReferences = _assemblies
            };
            var reporterMock = new Mock <IReporter>(MockBehavior.Strict);

            reporterMock.Setup(x => x.OnMutantTested(It.IsAny <Mutant>()));
            reporterMock.Setup(x => x.OnAllMutantsTested(It.IsAny <ReadOnlyProjectComponent>()));
            reporterMock.Setup(x => x.OnStartMutantTestRun(It.IsAny <IList <Mutant> >(), It.IsAny <IEnumerable <TestDescription> >()));

            var executorMock = new Mock <IMutationTestExecutor>(MockBehavior.Strict);

            executorMock.SetupGet(x => x.TestRunner).Returns(Mock.Of <ITestRunner>());
            executorMock.Setup(x => x.Test(It.IsAny <IList <Mutant> >(), It.IsAny <int>(), It.IsAny <TestUpdateHandler>()));

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

            var options = new StrykerOptions(fileSystem: new MockFileSystem(), basePath: basePath);

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

            var testResult = target.Test(options);

            executorMock.Verify(x => x.Test(It.IsAny <IList <Mutant> >(), It.IsAny <int>(), It.IsAny <TestUpdateHandler>()), Times.Never);
            reporterMock.Verify(x => x.OnStartMutantTestRun(It.IsAny <IList <Mutant> >(), It.IsAny <IEnumerable <TestDescription> >()), Times.Never);
            reporterMock.Verify(x => x.OnMutantTested(It.IsAny <Mutant>()), Times.Never);
            reporterMock.Verify(x => x.OnAllMutantsTested(It.IsAny <ReadOnlyProjectComponent>()), Times.Never);
            testResult.MutationScore.ShouldBe(double.NaN);
        }
Пример #8
0
        public void MutationTestProcess_ShouldCallExecutorForEveryMutant()
        {
            var mutant = new Mutant()
            {
                Id = 1
            };
            string basePath = @"c\ExampleProject.Test";
            var    input    = new MutationTestInput()
            {
                ProjectInfo = new Core.Initialisation.ProjectInfo()
                {
                    TestProjectPath = basePath,
                    ProjectContents = new FolderComposite()
                    {
                        Name     = "ProjectRoot",
                        Children = new Collection <ProjectComponent>()
                        {
                            new FileLeaf()
                            {
                                Name    = "SomeFile.cs",
                                Mutants = new Collection <Mutant>()
                                {
                                    mutant
                                }
                            }
                        }
                    },
                    ProjectUnderTestAssemblyName = "ExampleProject",
                    ProjectUnderTestPath         = @"c:\ExampleProject\",
                    TargetFramework = "netcoreapp2.0",
                },
                AssemblyReferences = new ReferenceProvider().GetReferencedAssemblies()
            };
            var reporterMock = new Mock <IReporter>(MockBehavior.Strict);

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

            var executorMock = new Mock <IMutationTestExecutor>(MockBehavior.Strict);

            executorMock.Setup(x => x.Test(It.IsAny <Mutant>()));

            var options = new StrykerOptions("c:/test", "Console", "", 2000, null, false, 1, 80, 60, 0);

            var target = new MutationTestProcess(input, reporterMock.Object, null, executorMock.Object);

            target.Test(options);

            executorMock.Verify(x => x.Test(mutant), Times.Once);
            reporterMock.Verify(x => x.OnMutantTested(mutant), Times.Once);
            reporterMock.Verify(x => x.OnAllMutantsTested(It.IsAny <ProjectComponent>()), Times.Once);
        }
        public void RunTestsSimultaneouslyWhenPossible()
        {
            var options      = new StrykerOptions();
            var mutantFilter = new Mock <IMutantFilter>(MockBehavior.Loose);

            using (var endProcess = new EventWaitHandle(false, EventResetMode.ManualReset))
            {
                var strykerOptions = new StrykerOptions(fileSystem: _fileSystem, abortTestOnFail: false);
                var mockVsTest     = BuildVsTestRunner(strykerOptions, endProcess, out var runner, strykerOptions.Optimizations);
                // make sure we have 4 mutants
                _projectContents.Add(new FileLeaf {
                    Mutants = new[] { new Mutant {
                                          Id = 2
                                      }, new Mutant {
                                          Id = 3
                                      } }
                });
                _testCases.Add(new TestCase("T2", _executorUri, _testAssemblyPath));
                _testCases.Add(new TestCase("T3", _executorUri, _testAssemblyPath));

                var input = new MutationTestInput {
                    ProjectInfo = _targetProject, TestRunner = runner, TimeoutMs = 100
                };
                foreach (var mutant in _targetProject.ProjectContents.Mutants)
                {
                    mutant.CoveringTests = new TestListDescription(null);
                }
                var mockReporter = new Mock <IReporter>();
                var tester       = new MutationTestProcess(input, mockReporter.Object, new MutationTestExecutor(input.TestRunner), fileSystem: _fileSystem, options: strykerOptions, mutantFilter: mutantFilter.Object);
                SetupMockCoverageRun(mockVsTest, new Dictionary <string, string> {
                    ["T0"] = "0;", ["T1"] = "1;"
                }, endProcess);
                tester.GetCoverage();
                SetupMockPartialTestRun(mockVsTest, new Dictionary <string, string> {
                    ["1,0"] = "T0=S,T1=F"
                }, endProcess);
                tester.Test(_projectContents.Mutants.Where(x => x.ResultStatus == MutantStatus.NotRun));

                _mutant.ResultStatus.ShouldBe(MutantStatus.Survived);
                _otherMutant.ResultStatus.ShouldBe(MutantStatus.Killed);
            }
        }
Пример #10
0
        public void MutationTestProcess_MutateShouldCallMutantOrchestrator()
        {
            var input = new MutationTestInput()
            {
                ProjectInfo = new ProjectInfo()
                {
                    TestProjectAnalyzerResult = new ProjectAnalyzerResult(null, null)
                    {
                        AssemblyPath = "/bin/Debug/netcoreapp2.1/TestName.dll",
                        Properties   = new Dictionary <string, string>()
                        {
                            { "TargetDir", "/bin/Debug/netcoreapp2.1" },
                            { "TargetFileName", "TestName.dll" }
                        }
                    },
                    ProjectUnderTestAnalyzerResult = new ProjectAnalyzerResult(null, null)
                    {
                        AssemblyPath = "/bin/Debug/netcoreapp2.1/TestName.dll",
                        Properties   = new Dictionary <string, string>()
                        {
                            { "TargetDir", "/bin/Debug/netcoreapp2.1" },
                            { "TargetFileName", "TestName.dll" }
                        }
                    },
                    ProjectContents = new FolderComposite()
                    {
                        Name     = Path.Combine(FilesystemRoot, "ExampleProject"),
                        Children = new Collection <ProjectComponent>()
                        {
                            new FileLeaf()
                            {
                                Name       = "Recursive.cs",
                                SourceCode = SourceFile
                            }
                        }
                    },
                },
                AssemblyReferences = _assemblies
            };

            var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { Path.Combine(FilesystemRoot, "ExampleProject", "Recursive.cs"), new MockFileData(SourceFile) },
                { Path.Combine(FilesystemRoot, "ExampleProject.Test", "bin", "Debug", "netcoreapp2.0", "ExampleProject.dll"), new MockFileData("Bytecode") },
                { Path.Combine(FilesystemRoot, "ExampleProject.Test", "obj", "Release", "netcoreapp2.0", "ExampleProject.dll"), new MockFileData("Bytecode") }
            });
            var mockMutants = new Collection <Mutant>()
            {
                new Mutant()
                {
                    Mutation = new Mutation()
                }
            };

            // create mocks
            var orchestratorMock         = new Mock <IMutantOrchestrator>(MockBehavior.Strict);
            var reporterMock             = new Mock <IReporter>(MockBehavior.Strict);
            var mutationTestExecutorMock = new Mock <IMutationTestExecutor>(MockBehavior.Strict);
            var compilingProcessMock     = new Mock <ICompilingProcess>(MockBehavior.Strict);

            // setup mocks
            reporterMock.Setup(x => x.OnMutantsCreated(It.IsAny <ProjectComponent>()));
            orchestratorMock.Setup(x => x.GetLatestMutantBatch()).Returns(mockMutants);
            orchestratorMock.Setup(x => x.Mutate(It.IsAny <SyntaxNode>())).Returns(CSharpSyntaxTree.ParseText(SourceFile).GetRoot());
            orchestratorMock.SetupAllProperties();
            compilingProcessMock.Setup(x => x.Compile(It.IsAny <IEnumerable <SyntaxTree> >(), It.IsAny <MemoryStream>(), true))
            .Returns(new CompilingProcessResult()
            {
                Success = true
            });

            var target = new MutationTestProcess(input,
                                                 reporterMock.Object,
                                                 mutationTestExecutorMock.Object,
                                                 orchestratorMock.Object,
                                                 compilingProcessMock.Object,
                                                 fileSystem);

            // start mutation process
            target.Mutate(new StrykerOptions(devMode: true, excludedMutations: new string[] { }));

            // verify the right methods were called
            orchestratorMock.Verify(x => x.Mutate(It.IsAny <SyntaxNode>()), Times.Once);
            reporterMock.Verify(x => x.OnMutantsCreated(It.IsAny <ProjectComponent>()), Times.Once);
        }
Пример #11
0
        public void MutationTestProcess_ShouldCallExecutorForEveryMutant()
        {
            var mutant = new Mutant {
                Id = 1
            };
            var otherMutant = new Mutant {
                Id = 2
            };
            string basePath = Path.Combine(FilesystemRoot, "ExampleProject.Test");
            var    input    = new MutationTestInput()
            {
                ProjectInfo = new ProjectInfo()
                {
                    ProjectUnderTestAnalyzerResult = new ProjectAnalyzerResult(null, null)
                    {
                        AssemblyPath = "/bin/Debug/netcoreapp2.1/TestName.dll",
                        Properties   = new Dictionary <string, string>()
                        {
                            { "TargetDir", "/bin/Debug/netcoreapp2.1" },
                            { "TargetFileName", "TestName.dll" }
                        }
                    },
                    ProjectContents = new FolderComposite()
                    {
                        Name     = "ProjectRoot",
                        Children = new Collection <ProjectComponent>()
                        {
                            new FileLeaf()
                            {
                                Name       = "SomeFile.cs",
                                SourceCode = SourceFile,
                                Mutants    = new List <Mutant>()
                                {
                                    mutant, otherMutant
                                }
                            }
                        }
                    }
                },
                AssemblyReferences = _assemblies
            };
            var reporterMock = new Mock <IReporter>(MockBehavior.Strict);

            reporterMock.Setup(x => x.OnMutantTested(It.IsAny <Mutant>()));
            reporterMock.Setup(x => x.OnAllMutantsTested(It.IsAny <ProjectComponent>()));
            reporterMock.Setup(x => x.OnStartMutantTestRun(It.IsAny <IList <Mutant> >()));

            var executorMock = new Mock <IMutationTestExecutor>(MockBehavior.Strict);

            executorMock.SetupGet(x => x.TestRunner).Returns(Mock.Of <ITestRunner>());
            executorMock.Setup(x => x.Test(It.IsAny <Mutant>(), It.IsAny <int>()));

            var options = new StrykerOptions(fileSystem: new MockFileSystem(), basePath: basePath);

            var target = new MutationTestProcess(input,
                                                 reporterMock.Object,
                                                 executorMock.Object);

            target.Test(options);

            executorMock.Verify(x => x.Test(mutant, It.IsAny <int>()), Times.Once);
            reporterMock.Verify(x => x.OnStartMutantTestRun(It.Is <IList <Mutant> >(y => y.Count == 2)), Times.Once);
            reporterMock.Verify(x => x.OnMutantTested(mutant), Times.Once);
            reporterMock.Verify(x => x.OnMutantTested(otherMutant), Times.Once);
            reporterMock.Verify(x => x.OnAllMutantsTested(It.IsAny <ProjectComponent>()), Times.Once);
        }
Пример #12
0
        public void MutationTestProcess_ShouldNotCallExecutorForNotCoveredMutants()
        {
            var mutant = new Mutant {
                Id = 1, ResultStatus = MutantStatus.Survived
            };
            var otherMutant = new Mutant {
                Id = 2, ResultStatus = MutantStatus.NotRun
            };
            var basePath = Path.Combine(FilesystemRoot, "ExampleProject.Test");
            var input    = new MutationTestInput()
            {
                ProjectInfo = new ProjectInfo()
                {
                    TestProjectAnalyzerResult = new ProjectAnalyzerResult(null, null)
                    {
                        AssemblyPath = "/bin/Debug/netcoreapp2.1/TestName.dll",
                        Properties   = new Dictionary <string, string>()
                        {
                            { "TargetDir", "/bin/Debug/netcoreapp2.1" },
                            { "TargetFileName", "TestName.dll" }
                        }
                    },
                    ProjectUnderTestAnalyzerResult = new ProjectAnalyzerResult(null, null)
                    {
                        AssemblyPath = "/bin/Debug/netcoreapp2.1/TestName.dll",
                        Properties   = new Dictionary <string, string>()
                        {
                            { "TargetDir", "/bin/Debug/netcoreapp2.1" },
                            { "TargetFileName", "TestName.dll" }
                        }
                    },
                    ProjectContents = new FolderComposite()
                    {
                        Name     = "ProjectRoot",
                        Children = new Collection <ProjectComponent>()
                        {
                            new FileLeaf()
                            {
                                Name    = "SomeFile.cs",
                                Mutants = new Collection <Mutant>()
                                {
                                    mutant, otherMutant
                                }
                            }
                        }
                    },
                },
                AssemblyReferences = new ReferenceProvider().GetReferencedAssemblies()
            };
            var reporterMock = new Mock <IReporter>(MockBehavior.Strict);

            reporterMock.Setup(x => x.OnMutantTested(It.IsAny <Mutant>()));
            reporterMock.Setup(x => x.OnAllMutantsTested(It.IsAny <ProjectComponent>()));
            reporterMock.Setup(x => x.OnStartMutantTestRun(It.IsAny <IList <Mutant> >()));

            var executorMock = new Mock <IMutationTestExecutor>(MockBehavior.Strict);

            executorMock.SetupGet(x => x.TestRunner).Returns(Mock.Of <ITestRunner>());
            executorMock.Setup(x => x.Test(It.IsAny <Mutant>(), It.IsAny <int>()));

            var options = new StrykerOptions(fileSystem: new MockFileSystem(), basePath: basePath);

            var target = new MutationTestProcess(input,
                                                 reporterMock.Object,
                                                 executorMock.Object);
            var coverage = new TestCoverageInfos();

            coverage.DeclareMappingForATest("toto", new [] { 2 });
            target.Optimize(coverage);

            target.Test(options);

            reporterMock.Verify(x => x.OnStartMutantTestRun(It.Is <IList <Mutant> >(y => y.Count == 1)), Times.Once);
            executorMock.Verify(x => x.Test(otherMutant, It.IsAny <int>()), Times.Once);
            reporterMock.Verify(x => x.OnMutantTested(otherMutant), Times.Once);
            reporterMock.Verify(x => x.OnAllMutantsTested(It.IsAny <ProjectComponent>()), Times.Once);
        }
Пример #13
0
        public void MutationTestProcess_MutateShouldCallMutantOrchestrator()
        {
            var input = new MutationTestInput()
            {
                ProjectInfo = new Core.Initialisation.ProjectInfo()
                {
                    TestProjectPath              = Path.Combine(_filesystemRoot, "ExampleProject.Test"),
                    ProjectUnderTestPath         = Path.Combine(_filesystemRoot, "ExampleProject"),
                    ProjectUnderTestAssemblyName = "ExampleProject",
                    TargetFramework              = "netcoreapp2.0",
                    ProjectContents              = new FolderComposite()
                    {
                        Name     = Path.Combine(_filesystemRoot, "ExampleProject"),
                        Children = new Collection <ProjectComponent>()
                        {
                            new FileLeaf()
                            {
                                Name       = "Recursive.cs",
                                SourceCode = _exampleFileContents
                            }
                        }
                    },
                },
                AssemblyReferences = new ReferenceProvider().GetReferencedAssemblies()
            };

            var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { Path.Combine(_filesystemRoot, "ExampleProject", "Recursive.cs"), new MockFileData(_exampleFileContents) },
                { Path.Combine(_filesystemRoot, "ExampleProject.Test", "bin", "Debug", "netcoreapp2.0", "ExampleProject.dll"), new MockFileData("Bytecode") },
                { Path.Combine(_filesystemRoot, "ExampleProject.Test", "obj", "Release", "netcoreapp2.0", "ExampleProject.dll"), new MockFileData("Bytecode") }
            });
            var mockMutants = new Collection <Mutant>()
            {
                new Mutant()
                {
                    Mutation = new Mutation()
                }
            };

            // create mocks
            var orchestratorMock         = new Mock <IMutantOrchestrator>(MockBehavior.Strict);
            var reporterMock             = new Mock <IReporter>(MockBehavior.Strict);
            var mutationTestExecutorMock = new Mock <IMutationTestExecutor>(MockBehavior.Strict);
            var compilingProcessMock     = new Mock <ICompilingProcess>(MockBehavior.Strict);

            // setup mocks
            reporterMock.Setup(x => x.OnMutantsCreated(It.IsAny <ProjectComponent>()));
            orchestratorMock.Setup(x => x.GetLatestMutantBatch()).Returns(mockMutants);
            orchestratorMock.Setup(x => x.Mutate(It.IsAny <SyntaxNode>())).Returns(CSharpSyntaxTree.ParseText(_exampleFileContents).GetRoot());
            orchestratorMock.SetupAllProperties();
            compilingProcessMock.Setup(x => x.Compile(It.IsAny <IEnumerable <SyntaxTree> >(), It.IsAny <MemoryStream>(), It.IsAny <bool>()))
            .Returns(new CompilingProcessResult()
            {
                Success = true
            });

            var target = new MutationTestProcess(input,
                                                 reporterMock.Object,
                                                 Enumerable.Empty <MutatorType>(),
                                                 mutationTestExecutorMock.Object,
                                                 orchestratorMock.Object,
                                                 compilingProcessMock.Object,
                                                 fileSystem);

            var options = new StrykerOptions();

            // start mutation process
            target.Mutate(options);

            // verify the right methods were called
            orchestratorMock.Verify(x => x.Mutate(It.IsAny <SyntaxNode>()), Times.Once);
            reporterMock.Verify(x => x.OnMutantsCreated(It.IsAny <ProjectComponent>()), Times.Once);
        }
Пример #14
0
        public void MutationTestProcess_MutateShouldWriteToDisk_IfCompilationIsSuccessful()
        {
            string basePath = Path.Combine(FilesystemRoot, "ExampleProject.Test");
            var    input    = new MutationTestInput()
            {
                ProjectInfo = new ProjectInfo()
                {
                    TestProjectAnalyzerResult = new ProjectAnalyzerResult(null, null)
                    {
                        AssemblyPath = Path.Combine(basePath, "bin", "Debug", "netcoreapp2.0", "TestName.dll"),
                        Properties   = new Dictionary <string, string>()
                        {
                            { "TargetDir", Path.Combine(basePath, "bin", "Debug", "netcoreapp2.0") },
                            { "TargetFileName", "TestName.dll" }
                        }
                    },
                    ProjectUnderTestAnalyzerResult = new ProjectAnalyzerResult(null, null)
                    {
                        AssemblyPath = Path.Combine(basePath, "bin", "Debug", "netcoreapp2.0", "ExampleProject.dll"),
                        Properties   = new Dictionary <string, string>()
                        {
                            { "TargetDir", Path.Combine(basePath, "bin", "Debug", "netcoreapp2.0") },
                            { "TargetFileName", "ExampleProject.dll" }
                        }
                    },
                    ProjectContents = new FolderComposite()
                    {
                        Name     = "ProjectRoot",
                        Children = new Collection <ProjectComponent>()
                        {
                            new FileLeaf
                            {
                                Name       = "SomeFile.cs",
                                SourceCode = SourceFile
                            }
                        }
                    }
                },
                AssemblyReferences = _assemblies
            };
            var mockMutants = new Collection <Mutant>()
            {
                new Mutant()
                {
                    Mutation = new Mutation()
                }
            };

            // create mocks
            var orchestratorMock         = new Mock <IMutantOrchestrator>(MockBehavior.Strict);
            var reporterMock             = new Mock <IReporter>(MockBehavior.Strict);
            var mutationTestExecutorMock = new Mock <IMutationTestExecutor>(MockBehavior.Strict);
            var compilingProcessMock     = new Mock <ICompilingProcess>(MockBehavior.Strict);
            var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { Path.Combine(FilesystemRoot, "SomeFile.cs"), new MockFileData("SomeFile") },
            });

            fileSystem.AddDirectory(Path.Combine(basePath, "bin", "Debug", "netcoreapp2.0"));

            // setup mocks
            orchestratorMock.Setup(x => x.Mutate(It.IsAny <SyntaxNode>())).Returns(CSharpSyntaxTree.ParseText(SourceFile).GetRoot());
            orchestratorMock.SetupAllProperties();
            orchestratorMock.Setup(x => x.GetLatestMutantBatch()).Returns(mockMutants);
            reporterMock.Setup(x => x.OnMutantsCreated(It.IsAny <ProjectComponent>()));
            compilingProcessMock.Setup(x => x.Compile(It.IsAny <IEnumerable <SyntaxTree> >(), It.IsAny <MemoryStream>(), It.IsAny <bool>()))
            .Returns(new CompilingProcessResult()
            {
                Success = true
            });

            var target = new MutationTestProcess(input,
                                                 reporterMock.Object,
                                                 mutationTestExecutorMock.Object,
                                                 orchestratorMock.Object,
                                                 compilingProcessMock.Object,
                                                 fileSystem);

            var options = new StrykerOptions();

            target.Mutate(options);

            // Verify the created assembly is written to disk on the right location
            string expectedPath = Path.Combine(basePath, "bin", "Debug", "netcoreapp2.0", "ExampleProject.dll");

            fileSystem.FileExists(expectedPath)
            .ShouldBeTrue($"The mutated Assembly was not written to disk, or not to the right location ({expectedPath}).");
        }
Пример #15
0
        public void MutationTestProcess_MutateShouldWriteToDisk_IfCompilationIsSuccessful()
        {
            Skip.IfNot(RunningOnWindows);

            string file1    = @"using System;

                namespace ExampleProject
                {
                    public class Recursive
                    {
                        public int Fibinacci(int len)
                        {
                            return Fibonacci(0, 1, 1, len);
                        }

                        private int Fibonacci(int a, int b, int counter, int len)
                        {
                            if (counter <= len)
                            {
                                Console.Write(""{0} "", a);
                                return Fibonacci(b, a + b, counter + 1, len);
                            }
                            return 0;
                        }
                    }
                }
                ";
            string basePath = @"C:\ExampleProject.Test";
            var    input    = new MutationTestInput()
            {
                ProjectInfo = new Core.Initialisation.ProjectInfo()
                {
                    TestProjectPath = basePath,
                    ProjectContents = new FolderComposite()
                    {
                        Name     = "ProjectRoot",
                        Children = new Collection <ProjectComponent>()
                        {
                            new FileLeaf()
                            {
                                Name       = "SomeFile.cs",
                                SourceCode = file1
                            }
                        }
                    },
                    ProjectUnderTestAssemblyName = "ExampleProject",
                    ProjectUnderTestPath         = @"C:\ExampleProject\",
                    TargetFramework = "netcoreapp2.0"
                },
                AssemblyReferences = new ReferenceProvider().GetReferencedAssemblies()
            };
            var mockMutants = new Collection <Mutant>()
            {
                new Mutant()
                {
                    Mutation = new Mutation()
                }
            };

            // create mocks
            var orchestratorMock         = new Mock <IMutantOrchestrator>(MockBehavior.Strict);
            var reporterMock             = new Mock <IReporter>(MockBehavior.Strict);
            var mutationTestExecutorMock = new Mock <IMutationTestExecutor>(MockBehavior.Strict);
            var compilingProcessMock     = new Mock <ICompilingProcess>(MockBehavior.Strict);
            var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { @"C:\SomeFile.cs", new MockFileData("SomeFile") },
            });

            // setup mocks
            orchestratorMock.Setup(x => x.Mutate(It.IsAny <SyntaxNode>())).Returns(CSharpSyntaxTree.ParseText(file1).GetRoot());
            orchestratorMock.SetupAllProperties();
            orchestratorMock.Setup(x => x.GetLatestMutantBatch()).Returns(mockMutants);
            reporterMock.Setup(x => x.OnMutantsCreated(It.IsAny <ProjectComponent>()));
            compilingProcessMock.Setup(x => x.Compile(It.IsAny <IEnumerable <SyntaxTree> >(), It.IsAny <MemoryStream>()))
            .Returns(new CompilingProcessResult()
            {
                Success = true
            });

            var options = new StrykerOptions("C:\test", "Console", "", 2000, null, false, 1, 80, 60, 0);

            var target = new MutationTestProcess(input,
                                                 reporterMock.Object,
                                                 null,
                                                 mutationTestExecutorMock.Object,
                                                 orchestratorMock.Object,
                                                 compilingProcessMock.Object,
                                                 fileSystem);

            target.Mutate();

            // Verify the created assembly is written to disk on the right location
            Assert.True(fileSystem.FileExists($@"{basePath}\bin\Debug\netcoreapp2.0\ExampleProject.dll"),
                        "The mutated Assembly was not written to disk, or not to the right location.");
        }
Пример #16
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);
        }
Пример #17
0
        public void ShouldThrowExceptionWhenOtherStatusThanNotRunIsPassed(MutantStatus status)
        {
            var mutant = new Mutant {
                Id = 1, ResultStatus = status
            };
            var basePath = Path.Combine(FilesystemRoot, "ExampleProject.Test");

            var folder = new CsharpFolderComposite();

            folder.Add(new CsharpFileLeaf()
            {
                Mutants = new Collection <Mutant>()
                {
                    mutant
                }
            });

            var input = new MutationTestInput()
            {
                ProjectInfo = new ProjectInfo()
                {
                    ProjectUnderTestAnalyzerResult = TestHelper.SetupProjectAnalyzerResult(properties: new Dictionary <string, string>()
                    {
                        { "TargetDir", "/bin/Debug/netcoreapp2.1" },
                        { "TargetFileName", "TestName.dll" }
                    }).Object,
                    TestProjectAnalyzerResults = new List <IAnalyzerResult> {
                        TestHelper.SetupProjectAnalyzerResult(properties: new Dictionary <string, string>()
                        {
                            { "TargetDir", "/bin/Debug/netcoreapp2.1" },
                            { "TargetFileName", "TestName.dll" },
                            { "Language", "C#" }
                        }).Object
                    },
                    ProjectContents = folder
                },
                AssemblyReferences = new ReferenceProvider().GetReferencedAssemblies()
            };
            var reporterMock = new Mock <IReporter>(MockBehavior.Strict);

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

            var runnerMock = new Mock <ITestRunner>();

            runnerMock.Setup(x => x.DiscoverNumberOfTests()).Returns(1);
            var executorMock = new Mock <IMutationTestExecutor>(MockBehavior.Strict);

            executorMock.SetupGet(x => x.TestRunner).Returns(runnerMock.Object);
            executorMock.Setup(x => x.Test(It.IsAny <IList <Mutant> >(), It.IsAny <int>(), It.IsAny <TestUpdateHandler>()));

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

            var options = new StrykerOptions(basePath: basePath, fileSystem: new MockFileSystem());

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

            Should.Throw <GeneralStrykerException>(() => target.Test(input.ProjectInfo.ProjectContents.Mutants));
        }
Пример #18
0
        public void ShouldCallMutantOrchestratorAndReporter()
        {
            var inputFile = new CsharpFileLeaf()
            {
                SourceCode = SourceFile,
                SyntaxTree = CSharpSyntaxTree.ParseText(SourceFile)
            };
            var folder = new CsharpFolderComposite();

            folder.Add(inputFile);
            var input = new MutationTestInput()
            {
                ProjectInfo = new ProjectInfo()
                {
                    ProjectUnderTestAnalyzerResult = TestHelper.SetupProjectAnalyzerResult(properties: new Dictionary <string, string>()
                    {
                        { "TargetDir", "/bin/Debug/netcoreapp2.1" },
                        { "TargetFileName", "TestName.dll" },
                        { "AssemblyName", "AssemblyName" },
                        { "Language", "C#" }
                    }).Object,
                    TestProjectAnalyzerResults = new List <IAnalyzerResult> {
                        TestHelper.SetupProjectAnalyzerResult(properties: new Dictionary <string, string>()
                        {
                            { "TargetDir", "/bin/Debug/netcoreapp2.1" },
                            { "TargetFileName", "TestName.dll" },
                            { "AssemblyName", "AssemblyName" },
                            { "Language", "C#" }
                        }).Object
                    },
                    ProjectContents = folder
                },
                AssemblyReferences = _assemblies
            };

            var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { Path.Combine(FilesystemRoot, "ExampleProject", "Recursive.cs"), new MockFileData(SourceFile) },
                { Path.Combine(FilesystemRoot, "ExampleProject.Test", "bin", "Debug", "netcoreapp2.0", "ExampleProject.dll"), new MockFileData("Bytecode") },
                { Path.Combine(FilesystemRoot, "ExampleProject.Test", "obj", "Release", "netcoreapp2.0", "ExampleProject.dll"), new MockFileData("Bytecode") }
            });

            var mutantToBeSkipped = new Mutant()
            {
                Mutation = new Mutation()
            };
            var mockMutants = new Collection <Mutant>()
            {
                new Mutant()
                {
                    Mutation = new Mutation()
                }, mutantToBeSkipped
            };

            // create mocks
            var orchestratorMock         = new Mock <MutantOrchestrator <SyntaxNode> >(MockBehavior.Strict);
            var reporterMock             = new Mock <IReporter>(MockBehavior.Strict);
            var mutationTestExecutorMock = new Mock <IMutationTestExecutor>(MockBehavior.Strict);
            var coverageAnalyzerMock     = new Mock <ICoverageAnalyser>(MockBehavior.Strict);

            // setup mocks
            orchestratorMock.Setup(x => x.GetLatestMutantBatch()).Returns(mockMutants);
            orchestratorMock.Setup(x => x.Mutate(It.IsAny <SyntaxNode>())).Returns(CSharpSyntaxTree.ParseText(SourceFile).GetRoot());
            orchestratorMock.SetupAllProperties();
            var options = new StrykerOptions(devMode: true, excludedMutations: new string[] { }, fileSystem: new MockFileSystem());

            var target = new MutationTestProcess(input,
                                                 reporterMock.Object,
                                                 mutationTestExecutorMock.Object,
                                                 orchestratorMock.Object,
                                                 fileSystem,
                                                 new BroadcastMutantFilter(Enumerable.Empty <IMutantFilter>()),
                                                 coverageAnalyzerMock.Object,
                                                 options);

            // start mutation process
            target.Mutate();

            target.FilterMutants();

            // verify the right methods were called
            orchestratorMock.Verify(x => x.Mutate(It.IsAny <SyntaxNode>()), Times.Once);
        }
Пример #19
0
        public void MutateShouldWriteToDisk_IfCompilationIsSuccessful()
        {
            var folder = new CsharpFolderComposite();

            folder.Add(new CsharpFileLeaf
            {
                SourceCode = SourceFile,
                SyntaxTree = CSharpSyntaxTree.ParseText(SourceFile)
            });

            var input = new MutationTestInput()
            {
                ProjectInfo = new ProjectInfo()
                {
                    ProjectUnderTestAnalyzerResult = TestHelper.SetupProjectAnalyzerResult(properties: new Dictionary <string, string>()
                    {
                        { "TargetDir", Path.Combine(FilesystemRoot, "ProjectUnderTest", "bin", "Debug", "netcoreapp2.0") },
                        { "TargetFileName", "ProjectUnderTest.dll" },
                        { "AssemblyName", "ProjectUnderTest.dll" },
                        { "Language", "C#" }
                    }).Object,
                    TestProjectAnalyzerResults = new List <IAnalyzerResult> {
                        TestHelper.SetupProjectAnalyzerResult(properties: new Dictionary <string, string>()
                        {
                            { "TargetDir", Path.Combine(FilesystemRoot, "TestProject", "bin", "Debug", "netcoreapp2.0") },
                            { "TargetFileName", "TestProject.dll" },
                            { "Language", "C#" }
                        }).Object
                    },
                    ProjectContents = folder
                },
                AssemblyReferences = _assemblies
            };
            var mockMutants = new Collection <Mutant>()
            {
                new Mutant()
                {
                    Mutation = new Mutation()
                }
            };

            // create mocks
            var orchestratorMock         = new Mock <MutantOrchestrator <SyntaxNode> >(MockBehavior.Strict);
            var reporterMock             = new Mock <IReporter>(MockBehavior.Strict);
            var mutationTestExecutorMock = new Mock <IMutationTestExecutor>(MockBehavior.Strict);
            var compilingProcessMock     = new Mock <ICompilingProcess>(MockBehavior.Strict);
            var coverageAnalyzerMock     = new Mock <ICoverageAnalyser>(MockBehavior.Strict);
            var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { Path.Combine(FilesystemRoot, "SomeFile.cs"), new MockFileData("SomeFile") },
            });

            fileSystem.AddDirectory(Path.Combine(FilesystemRoot, "TestProject", "bin", "Debug", "netcoreapp2.0"));

            // setup mocks
            orchestratorMock.Setup(x => x.Mutate(It.IsAny <SyntaxNode>())).Returns(CSharpSyntaxTree.ParseText(SourceFile).GetRoot());
            orchestratorMock.SetupAllProperties();
            orchestratorMock.Setup(x => x.GetLatestMutantBatch()).Returns(mockMutants);
            reporterMock.Setup(x => x.OnMutantsCreated(It.IsAny <ReadOnlyProjectComponent>()));

            var options = new StrykerOptions();
            var target  = new MutationTestProcess(input,
                                                  reporterMock.Object,
                                                  mutationTestExecutorMock.Object,
                                                  orchestratorMock.Object,
                                                  fileSystem,
                                                  new BroadcastMutantFilter(Enumerable.Empty <IMutantFilter>()),
                                                  coverageAnalyzerMock.Object,
                                                  options);

            target.Mutate();

            // Verify the created assembly is written to disk on the right location
            string expectedPath = Path.Combine(FilesystemRoot, "TestProject", "bin", "Debug", "netcoreapp2.0", "ProjectUnderTest.dll");

            fileSystem.ShouldContainFile(expectedPath);
        }
Пример #20
0
        public void ShouldCallExecutorForEveryMutant()
        {
            var mutant = new Mutant {
                Id = 1, MustRunAgainstAllTests = true
            };
            var otherMutant = new Mutant {
                Id = 2, MustRunAgainstAllTests = true
            };
            string basePath = Path.Combine(FilesystemRoot, "ExampleProject.Test");

            var folder = new CsharpFolderComposite();

            folder.Add(new CsharpFileLeaf()
            {
                SourceCode = SourceFile,
                Mutants    = new List <Mutant>()
                {
                    mutant, otherMutant
                }
            });

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

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

            var runnerMock = new Mock <ITestRunner>();

            runnerMock.Setup(x => x.DiscoverNumberOfTests()).Returns(1);
            var executorMock = new Mock <IMutationTestExecutor>(MockBehavior.Strict);

            executorMock.SetupGet(x => x.TestRunner).Returns(runnerMock.Object);
            executorMock.Setup(x => x.Test(It.IsAny <IList <Mutant> >(), It.IsAny <int>(), It.IsAny <TestUpdateHandler>()));

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

            var options = new StrykerOptions(basePath: basePath, fileSystem: new MockFileSystem());

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

            target.Test(input.ProjectInfo.ProjectContents.Mutants);

            executorMock.Verify(x => x.Test(new List <Mutant> {
                mutant
            }, It.IsAny <int>(), It.IsAny <TestUpdateHandler>()), Times.Once);
        }
        public void ShouldCallExecutorForEveryMutant()
        {
            var mutant = new Mutant {
                Id = 1, MustRunAgainstAllTests = true
            };
            var otherMutant = new Mutant {
                Id = 2, MustRunAgainstAllTests = true
            };
            string basePath = Path.Combine(FilesystemRoot, "ExampleProject.Test");

            var folder = new FolderComposite()
            {
                Name = "ProjectRoot"
            };

            folder.Add(new FileLeaf()
            {
                Name       = "SomeFile.cs",
                SourceCode = SourceFile,
                Mutants    = new List <Mutant>()
                {
                    mutant, otherMutant
                }
            });

            var input = new MutationTestInput()
            {
                ProjectInfo = new ProjectInfo()
                {
                    ProjectUnderTestAnalyzerResult = new ProjectAnalyzerResult(null, null)
                    {
                        AssemblyPath = "/bin/Debug/netcoreapp2.1/TestName.dll",
                        Properties   = new Dictionary <string, string>()
                        {
                            { "TargetDir", "/bin/Debug/netcoreapp2.1" },
                            { "TargetFileName", "TestName.dll" }
                        }
                    },
                    ProjectContents = folder
                },
                AssemblyReferences = _assemblies
            };
            var reporterMock = new Mock <IReporter>(MockBehavior.Strict);

            reporterMock.Setup(x => x.OnMutantTested(It.IsAny <Mutant>()));
            reporterMock.Setup(x => x.OnAllMutantsTested(It.IsAny <ReadOnlyProjectComponent>()));
            reporterMock.Setup(x => x.OnStartMutantTestRun(It.IsAny <IList <Mutant> >(), It.IsAny <IEnumerable <TestDescription> >()));

            var runnerMock = new Mock <ITestRunner>();

            runnerMock.Setup(x => x.DiscoverNumberOfTests()).Returns(1);
            var executorMock = new Mock <IMutationTestExecutor>(MockBehavior.Strict);

            executorMock.SetupGet(x => x.TestRunner).Returns(runnerMock.Object);
            executorMock.Setup(x => x.Test(It.IsAny <IList <Mutant> >(), It.IsAny <int>(), It.IsAny <TestUpdateHandler>()));

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

            var options = new StrykerOptions(fileSystem: new MockFileSystem(), basePath: basePath);

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

            target.Test(options);

            executorMock.Verify(x => x.Test(new List <Mutant> {
                mutant
            }, It.IsAny <int>(), It.IsAny <TestUpdateHandler>()), Times.Once);
            reporterMock.Verify(x => x.OnStartMutantTestRun(It.Is <IList <Mutant> >(y => y.Count == 2), It.IsAny <IEnumerable <TestDescription> >()), Times.Once);
            reporterMock.Verify(x => x.OnAllMutantsTested(It.IsAny <ReadOnlyProjectComponent>()), Times.Once);
        }
Пример #22
0
        public void MutationTestProcess_MutateShouldCallMutantOrchestrator()
        {
            Skip.IfNot(RunningOnWindows);

            string file1 = @"using System;

                namespace ExampleProject
                {
                    public class Recursive
                    {
                        public int Fibinacci(int len)
                        {
                            return Fibonacci(0, 1, 1, len);
                        }

                        private int Fibonacci(int a, int b, int counter, int len)
                        {
                            if (counter <= len)
                            {
                                Console.Write(""{0} "", a);
                                return Fibonacci(b, a + b, counter + 1, len);
                            }
                            return 0;
                        }
                    }
                }
                ";
            var    input = new MutationTestInput()
            {
                ProjectInfo = new Core.Initialisation.ProjectInfo()
                {
                    TestProjectPath              = @"c:\ExampleProject.Test",
                    ProjectUnderTestPath         = @"c:\ExampleProject",
                    ProjectUnderTestAssemblyName = "ExampleProject",
                    TargetFramework              = "netcoreapp2.0",
                    ProjectContents              = new FolderComposite()
                    {
                        Name     = @"c:\ExampleProject",
                        Children = new Collection <ProjectComponent>()
                        {
                            new FileLeaf()
                            {
                                Name       = "Recursive.cs",
                                SourceCode = file1
                            }
                        }
                    },
                },
                AssemblyReferences = new ReferenceProvider().GetReferencedAssemblies()
            };

            var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { @"c:\ExampleProject\Recursive.cs", new MockFileData(file1) },
                { @"c:\ExampleProject.Test\bin\Debug\netcoreapp2.0\ExampleProject.dll", new MockFileData("Bytecode") },
                { @"c:\ExampleProject.Test\obj\Release\netcoreapp2.0\ExampleProject.dll", new MockFileData("Bytecode") }
            });
            var mockMutants = new Collection <Mutant>()
            {
                new Mutant()
                {
                    Mutation = new Mutation()
                }
            };

            // create mocks
            var orchestratorMock         = new Mock <IMutantOrchestrator>(MockBehavior.Strict);
            var reporterMock             = new Mock <IReporter>(MockBehavior.Strict);
            var mutationTestExecutorMock = new Mock <IMutationTestExecutor>(MockBehavior.Strict);
            var compilingProcessMock     = new Mock <ICompilingProcess>(MockBehavior.Strict);

            // setup mocks
            reporterMock.Setup(x => x.OnMutantsCreated(It.IsAny <ProjectComponent>()));
            orchestratorMock.Setup(x => x.GetLatestMutantBatch()).Returns(mockMutants);
            orchestratorMock.Setup(x => x.Mutate(It.IsAny <SyntaxNode>())).Returns(CSharpSyntaxTree.ParseText(file1).GetRoot());
            orchestratorMock.SetupAllProperties();
            compilingProcessMock.Setup(x => x.Compile(It.IsAny <IEnumerable <SyntaxTree> >(), It.IsAny <MemoryStream>()))
            .Returns(new CompilingProcessResult()
            {
                Success = true
            });

            var options = new StrykerOptions("c:/test", "Console", "", 2000, null, false, 1, 80, 60, 0);
            var target  = new MutationTestProcess(input,
                                                  reporterMock.Object,
                                                  null,
                                                  mutationTestExecutorMock.Object,
                                                  orchestratorMock.Object,
                                                  compilingProcessMock.Object,
                                                  fileSystem);

            // start mutation process
            target.Mutate();

            // verify the right methods were called
            orchestratorMock.Verify(x => x.Mutate(It.IsAny <SyntaxNode>()), Times.Once);
            reporterMock.Verify(x => x.OnMutantsCreated(It.IsAny <ProjectComponent>()), Times.Once);
        }
Пример #23
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);
        }
Пример #24
0
        public void ShouldNotCallExecutorForNotCoveredMutants()
        {
            var mutant = new Mutant {
                Id = 1, ResultStatus = MutantStatus.Survived
            };
            var otherMutant = new Mutant {
                Id = 2, ResultStatus = MutantStatus.NotRun
            };
            var basePath = Path.Combine(FilesystemRoot, "ExampleProject.Test");
            var input    = new MutationTestInput()
            {
                ProjectInfo = new ProjectInfo()
                {
                    TestProjectAnalyzerResults = new List <ProjectAnalyzerResult> {
                        new ProjectAnalyzerResult(null, null)
                        {
                            AssemblyPath = "/bin/Debug/netcoreapp2.1/TestName.dll",
                            Properties   = new Dictionary <string, string>()
                            {
                                { "TargetDir", "/bin/Debug/netcoreapp2.1" },
                                { "TargetFileName", "TestName.dll" }
                            }
                        }
                    },
                    ProjectUnderTestAnalyzerResult = new ProjectAnalyzerResult(null, null)
                    {
                        AssemblyPath = "/bin/Debug/netcoreapp2.1/TestName.dll",
                        Properties   = new Dictionary <string, string>()
                        {
                            { "TargetDir", "/bin/Debug/netcoreapp2.1" },
                            { "TargetFileName", "TestName.dll" }
                        }
                    },
                    ProjectContents = new FolderComposite()
                    {
                        Name     = "ProjectRoot",
                        Children = new Collection <ProjectComponent>()
                        {
                            new FileLeaf()
                            {
                                Name    = "SomeFile.cs",
                                Mutants = new Collection <Mutant>()
                                {
                                    mutant, otherMutant
                                }
                            }
                        }
                    },
                },
                AssemblyReferences = new ReferenceProvider().GetReferencedAssemblies()
            };
            var reporterMock = new Mock <IReporter>(MockBehavior.Strict);

            reporterMock.Setup(x => x.OnMutantTested(It.IsAny <Mutant>()));
            reporterMock.Setup(x => x.OnAllMutantsTested(It.IsAny <ProjectComponent>()));
            reporterMock.Setup(x => x.OnStartMutantTestRun(It.IsAny <IList <Mutant> >(), It.IsAny <IEnumerable <TestDescription> >()));

            var runnerMock = new Mock <ITestRunner>();

            runnerMock.Setup(x => x.DiscoverNumberOfTests()).Returns(1);
            var executorMock = new Mock <IMutationTestExecutor>(MockBehavior.Strict);

            executorMock.SetupGet(x => x.TestRunner).Returns(runnerMock.Object);
            executorMock.Setup(x => x.Test(It.IsAny <IList <Mutant> >(), It.IsAny <int>(), It.IsAny <TestUpdateHandler>()));

            var options = new StrykerOptions(fileSystem: new MockFileSystem(), basePath: basePath);

            var target = new MutationTestProcess(input,
                                                 reporterMock.Object,
                                                 executorMock.Object,
                                                 mutantFilter: new BroadcastMutantFilter(Enumerable.Empty <IMutantFilter>()),
                                                 options: options);

            target.Test(options);

            reporterMock.Verify(x => x.OnStartMutantTestRun(It.Is <IList <Mutant> >(y => y.Count == 1), It.IsAny <IEnumerable <TestDescription> >()), Times.Once);
            executorMock.Verify(x => x.Test(new List <Mutant> {
                otherMutant
            }, It.IsAny <int>(), It.IsAny <TestUpdateHandler>()), Times.Once);
            reporterMock.Verify(x => x.OnAllMutantsTested(It.IsAny <ProjectComponent>()), Times.Once);
        }
Пример #25
0
        public void MutationTestProcess_MutateShouldWriteToDisk_IfCompilationIsSuccessful()
        {
            string basePath = Path.Combine(_filesystemRoot, "ExampleProject.Test");
            var    input    = new MutationTestInput()
            {
                ProjectInfo = new Core.Initialisation.ProjectInfo()
                {
                    TestProjectPath = basePath,
                    ProjectContents = new FolderComposite()
                    {
                        Name     = "ProjectRoot",
                        Children = new Collection <ProjectComponent>()
                        {
                            new FileLeaf()
                            {
                                Name       = "SomeFile.cs",
                                SourceCode = _exampleFileContents
                            }
                        }
                    },
                    ProjectUnderTestAssemblyName = "ExampleProject",
                    ProjectUnderTestPath         = Path.Combine(_filesystemRoot, "ExampleProject"),
                    TargetFramework = "netcoreapp2.0",
                    AppendTargetFrameworkToOutputPath = true
                },
                AssemblyReferences = new ReferenceProvider().GetReferencedAssemblies()
            };
            var mockMutants = new Collection <Mutant>()
            {
                new Mutant()
                {
                    Mutation = new Mutation()
                }
            };

            // create mocks
            var orchestratorMock         = new Mock <IMutantOrchestrator>(MockBehavior.Strict);
            var reporterMock             = new Mock <IReporter>(MockBehavior.Strict);
            var mutationTestExecutorMock = new Mock <IMutationTestExecutor>(MockBehavior.Strict);
            var compilingProcessMock     = new Mock <ICompilingProcess>(MockBehavior.Strict);
            var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { Path.Combine(_filesystemRoot, "SomeFile.cs"), new MockFileData("SomeFile") },
            });

            fileSystem.AddDirectory(Path.Combine(_filesystemRoot, "ExampleProject.Test", "bin", "Debug", "netcoreapp2.0"));

            // setup mocks
            orchestratorMock.Setup(x => x.Mutate(It.IsAny <SyntaxNode>())).Returns(CSharpSyntaxTree.ParseText(_exampleFileContents).GetRoot());
            orchestratorMock.SetupAllProperties();
            orchestratorMock.Setup(x => x.GetLatestMutantBatch()).Returns(mockMutants);
            reporterMock.Setup(x => x.OnMutantsCreated(It.IsAny <ProjectComponent>()));
            compilingProcessMock.Setup(x => x.Compile(It.IsAny <IEnumerable <SyntaxTree> >(), It.IsAny <MemoryStream>(), It.IsAny <bool>()))
            .Returns(new CompilingProcessResult()
            {
                Success = true
            });

            var target = new MutationTestProcess(input,
                                                 reporterMock.Object,
                                                 Enumerable.Empty <MutatorType>(),
                                                 mutationTestExecutorMock.Object,
                                                 orchestratorMock.Object,
                                                 compilingProcessMock.Object,
                                                 fileSystem);

            var options = new StrykerOptions();

            target.Mutate(options);

            // Verify the created assembly is written to disk on the right location
            Assert.True(fileSystem.FileExists(Path.Combine(basePath, "bin", "Debug", "netcoreapp2.0", "ExampleProject.dll")),
                        "The mutated Assembly was not written to disk, or not to the right location.");
        }
Пример #26
0
        public void FilterMutantsShouldCallMutantFilters()
        {
            var inputFile = new CsharpFileLeaf()
            {
                SourceCode = SourceFile,
                SyntaxTree = CSharpSyntaxTree.ParseText(SourceFile)
            };

            var folder = new CsharpFolderComposite();

            folder.Add(inputFile);

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

            var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { Path.Combine(FilesystemRoot, "ExampleProject", "Recursive.cs"), new MockFileData(SourceFile) },
                { Path.Combine(FilesystemRoot, "ExampleProject.Test", "bin", "Debug", "netcoreapp2.0", "ExampleProject.dll"), new MockFileData("Bytecode") },
                { Path.Combine(FilesystemRoot, "ExampleProject.Test", "obj", "Release", "netcoreapp2.0", "ExampleProject.dll"), new MockFileData("Bytecode") }
            });

            var mutantToBeSkipped = new Mutant()
            {
                Mutation = new Mutation()
            };
            var compileErrorMutant = new Mutant()
            {
                Mutation = new Mutation(), ResultStatus = MutantStatus.CompileError
            };
            var mockMutants = new Collection <Mutant>()
            {
                new Mutant()
                {
                    Mutation = new Mutation()
                }, mutantToBeSkipped, compileErrorMutant
            };

            // create mocks
            var orchestratorMock         = new Mock <MutantOrchestrator <SyntaxNode> >(MockBehavior.Strict);
            var reporterMock             = new Mock <IReporter>(MockBehavior.Strict);
            var mutationTestExecutorMock = new Mock <IMutationTestExecutor>(MockBehavior.Strict);
            var mutantFilterMock         = new Mock <IMutantFilter>(MockBehavior.Strict);
            var coverageAnalyzerMock     = new Mock <ICoverageAnalyser>(MockBehavior.Strict);

            // setup mocks
            reporterMock.Setup(x => x.OnMutantsCreated(It.IsAny <ReadOnlyProjectComponent>()));
            orchestratorMock.Setup(x => x.GetLatestMutantBatch()).Returns(mockMutants);
            orchestratorMock.Setup(x => x.Mutate(It.IsAny <SyntaxNode>())).Returns(CSharpSyntaxTree.ParseText(SourceFile).GetRoot());
            orchestratorMock.SetupAllProperties();
            mutantFilterMock.SetupGet(x => x.DisplayName).Returns("Mock filter");
            IEnumerable <Mutant> mutantsPassedToFilter = null;

            mutantFilterMock.Setup(x => x.FilterMutants(It.IsAny <IEnumerable <Mutant> >(), It.IsAny <ReadOnlyFileLeaf>(), It.IsAny <IStrykerOptions>()))
            .Callback <IEnumerable <Mutant>, ReadOnlyFileLeaf, IStrykerOptions>((mutants, _, __) => mutantsPassedToFilter = mutants)
            .Returns((IEnumerable <Mutant> mutants, ReadOnlyFileLeaf file, IStrykerOptions o) => mutants.Take(1));

            var options = new StrykerOptions(devMode: true, excludedMutations: new string[] { }, fileSystem: new MockFileSystem());

            var target = new MutationTestProcess(input,
                                                 reporterMock.Object,
                                                 mutationTestExecutorMock.Object,
                                                 orchestratorMock.Object,
                                                 fileSystem,
                                                 new BroadcastMutantFilter(new[] { mutantFilterMock.Object }),
                                                 coverageAnalyzerMock.Object,
                                                 options);

            // start mutation process
            target.Mutate();

            target.FilterMutants();

            // verify that compiler error mutants are not passed to filter
            mutantsPassedToFilter.ShouldNotContain(compileErrorMutant);

            // verify that filtered mutants are skipped
            inputFile.Mutants.ShouldContain(mutantToBeSkipped);
            mutantToBeSkipped.ResultStatus.ShouldBe(MutantStatus.Ignored);
        }
        public void MutateShouldCallMutantFilters()
        {
            var inputFile = new FileLeaf()
            {
                Name       = "Recursive.cs",
                SourceCode = SourceFile,
                SyntaxTree = CSharpSyntaxTree.ParseText(SourceFile)
            };

            var input = new MutationTestInput()
            {
                ProjectInfo = new ProjectInfo()
                {
                    TestProjectAnalyzerResults = new List <ProjectAnalyzerResult> {
                        new ProjectAnalyzerResult(null, null)
                        {
                            AssemblyPath = "/bin/Debug/netcoreapp2.1/TestName.dll",
                            Properties   = new Dictionary <string, string>()
                            {
                                { "TargetDir", "/bin/Debug/netcoreapp2.1" },
                                { "AssemblyName", "TestName" },
                            }
                        }
                    },
                    ProjectUnderTestAnalyzerResult = new ProjectAnalyzerResult(null, null)
                    {
                        AssemblyPath = "/bin/Debug/netcoreapp2.1/TestName.dll",
                        Properties   = new Dictionary <string, string>()
                        {
                            { "TargetDir", "/bin/Debug/netcoreapp2.1" },
                            { "AssemblyName", "TestName" },
                        }
                    },
                    ProjectContents = new FolderComposite()
                    {
                        Name     = Path.Combine(FilesystemRoot, "ExampleProject"),
                        Children = new Collection <ProjectComponent>()
                        {
                            inputFile,
                        }
                    },
                },
                AssemblyReferences = _assemblies
            };

            var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { Path.Combine(FilesystemRoot, "ExampleProject", "Recursive.cs"), new MockFileData(SourceFile) },
                { Path.Combine(FilesystemRoot, "ExampleProject.Test", "bin", "Debug", "netcoreapp2.0", "ExampleProject.dll"), new MockFileData("Bytecode") },
                { Path.Combine(FilesystemRoot, "ExampleProject.Test", "obj", "Release", "netcoreapp2.0", "ExampleProject.dll"), new MockFileData("Bytecode") }
            });

            var mutantToBeSkipped = new Mutant()
            {
                Mutation = new Mutation()
            };
            var mockMutants = new Collection <Mutant>()
            {
                new Mutant()
                {
                    Mutation = new Mutation()
                }, mutantToBeSkipped
            };

            // create mocks
            var orchestratorMock         = new Mock <IMutantOrchestrator>(MockBehavior.Strict);
            var reporterMock             = new Mock <IReporter>(MockBehavior.Strict);
            var mutationTestExecutorMock = new Mock <IMutationTestExecutor>(MockBehavior.Strict);
            var compilingProcessMock     = new Mock <ICompilingProcess>(MockBehavior.Strict);
            var mutantFilterMock         = new Mock <IMutantFilter>(MockBehavior.Strict);

            // setup mocks
            reporterMock.Setup(x => x.OnMutantsCreated(It.IsAny <ProjectComponent>()));
            orchestratorMock.Setup(x => x.GetLatestMutantBatch()).Returns(mockMutants);
            orchestratorMock.Setup(x => x.Mutate(It.IsAny <SyntaxNode>())).Returns(CSharpSyntaxTree.ParseText(SourceFile).GetRoot());
            orchestratorMock.SetupAllProperties();
            compilingProcessMock.Setup(x => x.Compile(It.IsAny <IEnumerable <SyntaxTree> >(), It.IsAny <MemoryStream>(), It.IsAny <MemoryStream>(), true))
            .Returns(new CompilingProcessResult()
            {
                Success = true
            });
            mutantFilterMock.SetupGet(x => x.DisplayName).Returns("Mock filter");
            mutantFilterMock.Setup(x => x.FilterMutants(It.IsAny <IEnumerable <Mutant> >(), It.IsAny <FileLeaf>(), It.IsAny <StrykerOptions>()))
            .Returns((IEnumerable <Mutant> mutants, FileLeaf file, StrykerOptions o) => mutants.Take(1));


            var options = new StrykerOptions(devMode: true, excludedMutations: new string[] { });

            var target = new MutationTestProcess(input,
                                                 reporterMock.Object,
                                                 mutationTestExecutorMock.Object,
                                                 orchestratorMock.Object,
                                                 compilingProcessMock.Object,
                                                 fileSystem,
                                                 options,
                                                 new BroadcastMutantFilter(new[] { mutantFilterMock.Object }));

            // start mutation process
            target.Mutate();

            // verify that filtered mutants are skipped
            inputFile.Mutants.ShouldContain(mutantToBeSkipped);
            mutantToBeSkipped.ResultStatus.ShouldBe(MutantStatus.Ignored);
        }