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