public void Stryker_ShouldInvokeAllProcesses()
        {
            var projectOrchestratorMock = new Mock <IProjectOrchestrator>(MockBehavior.Strict);
            var mutationTestProcessMock = new Mock <IMutationTestProcess>(MockBehavior.Strict);
            var reporterFactoryMock     = new Mock <IReporterFactory>(MockBehavior.Strict);
            var reporterMock            = new Mock <IReporter>(MockBehavior.Strict);
            var fileSystemMock          = new MockFileSystem();

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

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

            var mutationTestInput = new MutationTestInput()
            {
                ProjectInfo = new ProjectInfo()
                {
                    ProjectContents = folder
                },
            };
            var options = new StrykerOptions(basePath: "c:/test", fileSystem: fileSystemMock);

            projectOrchestratorMock.Setup(x => x.MutateProjects(options, It.IsAny <IReporter>()))
            .Returns(new List <IMutationTestProcess>()
            {
                mutationTestProcessMock.Object
            });

            reporterFactoryMock.Setup(x => x.Create(It.IsAny <StrykerOptions>(), It.IsAny <IGitInfoProvider>())).Returns(reporterMock.Object);

            reporterMock.Setup(x => x.OnMutantsCreated(It.IsAny <IReadOnlyProjectComponent>()));
            reporterMock.Setup(x => x.OnStartMutantTestRun(It.IsAny <IEnumerable <IReadOnlyMutant> >()));
            reporterMock.Setup(x => x.OnAllMutantsTested(It.IsAny <IReadOnlyProjectComponent>()));

            mutationTestProcessMock.SetupGet(x => x.Input).Returns(mutationTestInput);
            mutationTestProcessMock.Setup(x => x.GetCoverage());
            mutationTestProcessMock.Setup(x => x.Test(It.IsAny <IEnumerable <Mutant> >()))
            .Returns(new StrykerRunResult(It.IsAny <StrykerOptions>(), It.IsAny <double>()));

            var target = new StrykerRunner(projectOrchestratorMock.Object, reporterFactory: reporterFactoryMock.Object);

            target.RunMutationTest(options);

            projectOrchestratorMock.Verify(x => x.MutateProjects(options, It.IsAny <IReporter>()), Times.Once);
            mutationTestProcessMock.Verify(x => x.GetCoverage(), Times.Once);
            mutationTestProcessMock.Verify(x => x.Test(It.IsAny <IEnumerable <Mutant> >()), Times.Once);
            reporterMock.Verify(x => x.OnMutantsCreated(It.IsAny <IReadOnlyProjectComponent>()), Times.Once);
            reporterMock.Verify(x => x.OnStartMutantTestRun(It.IsAny <IEnumerable <IReadOnlyMutant> >()), Times.Once);
            reporterMock.Verify(x => x.OnAllMutantsTested(It.IsAny <IReadOnlyProjectComponent>()), Times.Once);
        }
        public void ShouldStop_WhenAllMutationsWereIgnored()
        {
            var projectOrchestratorMock = new Mock <IProjectOrchestrator>(MockBehavior.Strict);
            var mutationTestProcessMock = new Mock <IMutationTestProcess>(MockBehavior.Strict);
            var reporterFactoryMock     = new Mock <IReporterFactory>(MockBehavior.Strict);
            var reporterMock            = new Mock <IReporter>(MockBehavior.Strict);
            var fileSystemMock          = new MockFileSystem();

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

            folder.Add(new FileLeaf
            {
                Name    = "SomeFile.cs",
                Mutants = new Collection <Mutant>()
                {
                    new Mutant()
                    {
                        Id = 1, ResultStatus = MutantStatus.Ignored
                    }
                }
            });
            var mutationTestInput = new MutationTestInput()
            {
                ProjectInfo = new ProjectInfo()
                {
                    ProjectContents = folder
                }
            };
            var options = new StrykerOptions(basePath: "c:/test", fileSystem: fileSystemMock, coverageAnalysis: "off");

            projectOrchestratorMock.Setup(x => x.MutateProjects(options, It.IsAny <IReporter>()))
            .Returns(new List <IMutationTestProcess>()
            {
                mutationTestProcessMock.Object
            });

            mutationTestProcessMock.SetupGet(x => x.Input).Returns(mutationTestInput);

            reporterFactoryMock.Setup(x => x.Create(It.IsAny <StrykerOptions>(), It.IsAny <IGitInfoProvider>())).Returns(reporterMock.Object);

            reporterMock.Setup(x => x.OnMutantsCreated(It.IsAny <IReadOnlyProjectComponent>()));
            reporterMock.Setup(x => x.OnStartMutantTestRun(It.IsAny <IEnumerable <IReadOnlyMutant> >()));

            var target = new StrykerRunner(projectOrchestratorMock.Object, reporterFactory: reporterFactoryMock.Object);

            var result = target.RunMutationTest(options);

            result.MutationScore.ShouldBe(double.NaN);

            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 <IReadOnlyProjectComponent>()), Times.Never);
        }
Beispiel #3
0
        public void Stryker_ShouldInvokeAllProcesses()
        {
            var initialisationMock      = new Mock <IInitialisationProcess>(MockBehavior.Strict);
            var mutationTestProcessMock = new Mock <IMutationTestProcess>(MockBehavior.Strict);
            var fileSystemMock          = new MockFileSystem();
            var reporterMock            = new Mock <IReporter>(MockBehavior.Loose);

            var folder = new FolderComposite()
            {
                Name = "ProjectRoot"
            };
            var file = new FileLeaf()
            {
                Name    = "SomeFile.cs",
                Mutants = new List <Mutant> {
                    new Mutant {
                        Id = 1
                    }
                }
            };

            folder.Add(file);

            var mutationTestInput = new MutationTestInput()
            {
                ProjectInfo = new ProjectInfo()
                {
                    ProjectContents = folder
                },
            };

            initialisationMock.Setup(x => x.Initialize(It.IsAny <StrykerOptions>())).Returns(mutationTestInput);
            var options = new StrykerOptions(basePath: "c:/test", fileSystem: fileSystemMock);
            var nbTests = 0;

            initialisationMock.Setup(x => x.InitialTest(options, out nbTests)).Returns(0);

            mutationTestProcessMock.Setup(x => x.Mutate());
            mutationTestProcessMock.Setup(x => x.GetCoverage());
            mutationTestProcessMock.Setup(x => x.FilterMutants());
            mutationTestProcessMock.Setup(x => x.Test(It.IsAny <StrykerOptions>()))
            .Returns(new StrykerRunResult(It.IsAny <StrykerOptions>(), It.IsAny <double>()));



            var target = new StrykerRunner(initialisationMock.Object, mutationTestProcessMock.Object, reporter: reporterMock.Object);

            target.RunMutationTest(options);

            initialisationMock.Verify(x => x.Initialize(It.IsAny <StrykerOptions>()), Times.Once);
            mutationTestProcessMock.Verify(x => x.Mutate(), Times.Once);
            mutationTestProcessMock.Verify(x => x.Test(It.IsAny <StrykerOptions>()), Times.Once);
        }
Beispiel #4
0
        public void Stryker_ShouldInvokeAllProcesses()
        {
            var initialisationMock      = new Mock <IInitialisationProcess>(MockBehavior.Strict);
            var mutationTestProcessMock = new Mock <IMutationTestProcess>(MockBehavior.Strict);
            var fileSystemMock          = new MockFileSystem();

            initialisationMock.Setup(x => x.Initialize(It.IsAny <StrykerOptions>())).Returns(new MutationTestInput()
            {
                ProjectInfo = new ProjectInfo()
                {
                    ProjectContents = new FolderComposite()
                    {
                        Name     = "ProjectRoot",
                        Children = new Collection <ProjectComponent>()
                        {
                            new FileLeaf()
                            {
                                Name    = "SomeFile.cs",
                                Mutants = new List <Mutant> {
                                    new Mutant {
                                        Id = 1
                                    }
                                }
                            }
                        }
                    }
                },
            });
            var options        = new StrykerOptions(basePath: "c:/test", fileSystem: fileSystemMock);
            var coveredMutants = new TestCoverageInfos();

            coveredMutants.DeclareMappingForATest(new TestDescription("1", "SomeTest"), new[] { 2, 3 }, new[] { 2 });
            var nbTests = 0;

            initialisationMock.Setup(x => x.InitialTest(It.IsAny <StrykerOptions>(), out nbTests)).Returns(0);
            initialisationMock.Setup(x => x.GetCoverage(It.IsAny <StrykerOptions>())).Returns(coveredMutants);

            mutationTestProcessMock.Setup(x => x.Mutate());
            mutationTestProcessMock.Setup(x => x.Test(It.IsAny <StrykerOptions>()))
            .Returns(new StrykerRunResult(It.IsAny <StrykerOptions>(), It.IsAny <decimal?>()));

            var target = new StrykerRunner(initialisationMock.Object, mutationTestProcessMock.Object, fileSystemMock);


            target.RunMutationTest(options);

            initialisationMock.Verify(x => x.Initialize(It.IsAny <StrykerOptions>()), Times.Once);
            mutationTestProcessMock.Verify(x => x.Mutate(), Times.Once);
            mutationTestProcessMock.Verify(x => x.Test(It.IsAny <StrykerOptions>()), Times.Once);
        }
Beispiel #5
0
        public void Stryker_ShouldInvokeAllProcesses()
        {
            string basePath = @"c:\TestProject\";

            var initialisationMock      = new Mock <IInitialisationProcess>(MockBehavior.Strict);
            var mutationTestProcessMock = new Mock <IMutationTestProcess>(MockBehavior.Strict);
            var fileSystemMock          = new MockFileSystem();

            initialisationMock.Setup(x => x.Initialize(It.IsAny <StrykerOptions>())).Returns(new MutationTestInput()
            {
                ProjectInfo = new ProjectInfo()
                {
                    TestProjectPath = basePath,
                    ProjectContents = new FolderComposite()
                    {
                        Name     = "ProjectRoot",
                        Children = new Collection <ProjectComponent>()
                        {
                            new FileLeaf()
                            {
                                Name = "SomeFile.cs"
                            }
                        }
                    },
                    ProjectUnderTestAssemblyName = "ExampleProject.dll",
                    ProjectUnderTestPath         = @"c:\ExampleProject\",
                    TargetFramework = "netcoreapp2.0"
                },
            });
            var options = new StrykerOptions(basePath: "c:/test", fileSystem: fileSystemMock);

            mutationTestProcessMock.Setup(x => x.Mutate(options));
            mutationTestProcessMock.Setup(x => x.Test(It.IsAny <StrykerOptions>()))
            .Returns(new StrykerRunResult(It.IsAny <StrykerOptions>(), It.IsAny <decimal?>()));

            var target = new StrykerRunner(initialisationMock.Object, mutationTestProcessMock.Object, fileSystemMock);

            target.RunMutationTest(options);

            initialisationMock.Verify(x => x.Initialize(It.IsAny <StrykerOptions>()), Times.Once);
            mutationTestProcessMock.Verify(x => x.Mutate(options), Times.Once);
            mutationTestProcessMock.Verify(x => x.Test(It.IsAny <StrykerOptions>()), Times.Once);
        }
        public void Stryker_ShouldInvokeAllProcesses()
        {
            var projectOrchestratorMock = new Mock <IProjectOrchestrator>(MockBehavior.Strict);
            var mutationTestProcessMock = new Mock <IMutationTestProcess>(MockBehavior.Strict);
            var reporterFactoryMock     = new Mock <IReporterFactory>(MockBehavior.Strict);
            var reporterMock            = new Mock <IReporter>(MockBehavior.Strict);
            var fileSystemMock          = new MockFileSystem();

            var folder = new CsharpFolderComposite();

            folder.Add(new CsharpFileLeaf()
            {
                Mutants = new List <Mutant> {
                    new Mutant {
                        Id = 1
                    }
                }
            });

            var mutationTestInput = new MutationTestInput()
            {
                ProjectInfo = new ProjectInfo()
                {
                    ProjectContents = folder
                },
            };
            var options = new StrykerOptions(basePath: "c:/test", fileSystem: fileSystemMock);

            projectOrchestratorMock.Setup(x => x.MutateProjects(options, It.IsAny <IReporter>()))
            .Returns(new List <IMutationTestProcess>()
            {
                mutationTestProcessMock.Object
            });

            reporterFactoryMock.Setup(x => x.Create(It.IsAny <StrykerOptions>(), It.IsAny <IGitInfoProvider>())).Returns(reporterMock.Object);

            reporterMock.Setup(x => x.OnStartMutantTestRun(It.IsAny <IEnumerable <IReadOnlyMutant> >()));
            reporterMock.Setup(x => x.OnAllMutantsTested(It.IsAny <IReadOnlyProjectComponent>()));

            mutationTestProcessMock.SetupGet(x => x.Input).Returns(mutationTestInput);
            mutationTestProcessMock.Setup(x => x.GetCoverage());
            mutationTestProcessMock.Setup(x => x.Test(It.IsAny <IEnumerable <Mutant> >()))
            .Returns(new StrykerRunResult(It.IsAny <StrykerOptions>(), It.IsAny <double>()));

            // Set up sequence-critical methods:
            // * FilterMutants must be called before OnMutantsCreated to get valid reports
            var seq = new MockSequence();

            mutationTestProcessMock.InSequence(seq).Setup(x => x.FilterMutants());
            reporterMock.InSequence(seq).Setup(x => x.OnMutantsCreated(It.IsAny <IReadOnlyProjectComponent>()));

            var target = new StrykerRunner(projectOrchestratorMock.Object, reporterFactory: reporterFactoryMock.Object);

            target.RunMutationTest(options);

            projectOrchestratorMock.Verify(x => x.MutateProjects(options, It.IsAny <IReporter>()), Times.Once);
            mutationTestProcessMock.Verify(x => x.GetCoverage(), Times.Once);
            mutationTestProcessMock.Verify(x => x.Test(It.IsAny <IEnumerable <Mutant> >()), Times.Once);
            reporterMock.Verify(x => x.OnMutantsCreated(It.IsAny <IReadOnlyProjectComponent>()), Times.Once);
            reporterMock.Verify(x => x.OnStartMutantTestRun(It.IsAny <IEnumerable <IReadOnlyMutant> >()), Times.Once);
            reporterMock.Verify(x => x.OnAllMutantsTested(It.IsAny <IReadOnlyProjectComponent>()), Times.Once);
        }
Beispiel #7
0
        public void ShouldStop_WhenAllMutationsWereIgnored()
        {
            var projectOrchestratorMock = new Mock <IProjectOrchestrator>(MockBehavior.Strict);
            var mutationTestProcessMock = new Mock <IMutationTestProcess>(MockBehavior.Strict);
            var reporterFactoryMock     = new Mock <IReporterFactory>(MockBehavior.Strict);
            var reporterMock            = new Mock <IReporter>(MockBehavior.Strict);
            var inputsMock     = new Mock <IStrykerInputs>(MockBehavior.Strict);
            var fileSystemMock = new MockFileSystem();

            var folder = new CsharpFolderComposite();

            folder.Add(new CsharpFileLeaf
            {
                Mutants = new Collection <Mutant>()
                {
                    new Mutant()
                    {
                        Id = 1, ResultStatus = MutantStatus.Ignored
                    }
                }
            });
            var mutationTestInput = new MutationTestInput()
            {
                ProjectInfo = new ProjectInfo(new MockFileSystem())
                {
                    ProjectContents = folder
                }
            };

            inputsMock.Setup(x => x.ValidateAll()).Returns(new StrykerOptions
            {
                BasePath         = "C:/test",
                OptimizationMode = OptimizationModes.None,
                LogOptions       = new LogOptions()
            });

            projectOrchestratorMock.Setup(x => x.MutateProjects(It.IsAny <StrykerOptions>(), It.IsAny <IReporter>()))
            .Returns(new List <IMutationTestProcess>()
            {
                mutationTestProcessMock.Object
            });

            mutationTestProcessMock.Setup(x => x.FilterMutants());
            mutationTestProcessMock.SetupGet(x => x.Input).Returns(mutationTestInput);

            reporterFactoryMock.Setup(x => x.Create(It.IsAny <StrykerOptions>(), It.IsAny <IGitInfoProvider>())).Returns(reporterMock.Object);

            reporterMock.Setup(x => x.OnMutantsCreated(It.IsAny <IReadOnlyProjectComponent>()));
            reporterMock.Setup(x => x.OnStartMutantTestRun(It.IsAny <IEnumerable <IReadOnlyMutant> >()));
            reporterMock.Setup(x => x.OnAllMutantsTested(It.IsAny <IReadOnlyProjectComponent>()));

            var target = new StrykerRunner(reporterFactory: reporterFactoryMock.Object);

            var result = target.RunMutationTest(inputsMock.Object, new LoggerFactory(), projectOrchestratorMock.Object);

            result.MutationScore.ShouldBe(double.NaN);

            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 <IReadOnlyProjectComponent>()), Times.Once);
        }
Beispiel #8
0
        public void Stryker_ShouldInvokeAllProcesses()
        {
            var projectOrchestratorMock = new Mock <IProjectOrchestrator>(MockBehavior.Strict);
            var mutationTestProcessMock = new Mock <IMutationTestProcess>(MockBehavior.Strict);
            var reporterFactoryMock     = new Mock <IReporterFactory>(MockBehavior.Strict);
            var reporterMock            = new Mock <IReporter>(MockBehavior.Strict);
            var inputsMock     = new Mock <IStrykerInputs>(MockBehavior.Strict);
            var fileSystemMock = new MockFileSystem();

            var folder = new CsharpFolderComposite();

            folder.Add(new CsharpFileLeaf()
            {
                Mutants = new List <Mutant> {
                    new Mutant {
                        Id = 1
                    }
                }
            });

            var projectInfo = Mock.Of <ProjectInfo>();

            projectInfo.ProjectContents = folder;
            Mock.Get(projectInfo).Setup(p => p.RestoreOriginalAssembly());
            var mutationTestInput = new MutationTestInput()
            {
                ProjectInfo = projectInfo
            };

            inputsMock.Setup(x => x.ValidateAll()).Returns(new StrykerOptions
            {
                BasePath         = "C:/test",
                LogOptions       = new LogOptions(),
                OptimizationMode = OptimizationModes.SkipUncoveredMutants
            });

            projectOrchestratorMock.Setup(x => x.MutateProjects(It.IsAny <StrykerOptions>(), It.IsAny <IReporter>()))
            .Returns(new List <IMutationTestProcess>()
            {
                mutationTestProcessMock.Object
            });

            reporterFactoryMock.Setup(x => x.Create(It.IsAny <StrykerOptions>(), It.IsAny <IGitInfoProvider>())).Returns(reporterMock.Object);

            reporterMock.Setup(x => x.OnStartMutantTestRun(It.IsAny <IEnumerable <IReadOnlyMutant> >()));
            reporterMock.Setup(x => x.OnAllMutantsTested(It.IsAny <IReadOnlyProjectComponent>()));

            mutationTestProcessMock.SetupGet(x => x.Input).Returns(mutationTestInput);
            mutationTestProcessMock.Setup(x => x.GetCoverage());
            mutationTestProcessMock.Setup(x => x.Test(It.IsAny <IEnumerable <Mutant> >()))
            .Returns(new StrykerRunResult(It.IsAny <StrykerOptions>(), It.IsAny <double>()));
            mutationTestProcessMock.Setup(x => x.Restore());

            // Set up sequence-critical methods:
            // * FilterMutants must be called before OnMutantsCreated to get valid reports
            var seq = new MockSequence();

            mutationTestProcessMock.InSequence(seq).Setup(x => x.FilterMutants());
            reporterMock.InSequence(seq).Setup(x => x.OnMutantsCreated(It.IsAny <IReadOnlyProjectComponent>()));

            var target = new StrykerRunner(reporterFactory: reporterFactoryMock.Object);

            target.RunMutationTest(inputsMock.Object, new LoggerFactory(), projectOrchestratorMock.Object);

            projectOrchestratorMock.Verify(x => x.MutateProjects(It.Is <StrykerOptions>(x => x.BasePath == "C:/test"), It.IsAny <IReporter>()), Times.Once);
            mutationTestProcessMock.Verify(x => x.GetCoverage(), Times.Once);
            mutationTestProcessMock.Verify(x => x.Test(It.IsAny <IEnumerable <Mutant> >()), Times.Once);
            reporterMock.Verify(x => x.OnMutantsCreated(It.IsAny <IReadOnlyProjectComponent>()), Times.Once);
            reporterMock.Verify(x => x.OnStartMutantTestRun(It.IsAny <IEnumerable <IReadOnlyMutant> >()), Times.Once);
            reporterMock.Verify(x => x.OnAllMutantsTested(It.IsAny <IReadOnlyProjectComponent>()), Times.Once);
        }