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); }
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); }