public void ShouldOnlyMutateChangedFiles() { // Arrange var options = new StrykerOptions(diff: true); var baselineProvider = new Mock <IBaselineProvider>(); var diffProvider = new Mock <IDiffProvider>(MockBehavior.Loose); var branchProvider = new Mock <IGitInfoProvider>(); string myFile = Path.Combine("C:/test/", "myfile.cs");; diffProvider.Setup(x => x.ScanDiff()).Returns(new DiffResult() { ChangedSourceFiles = new Collection <string>() { myFile } }); var target = new DiffMutantFilter(options, diffProvider.Object, baselineProvider.Object, branchProvider.Object); var file = new CsharpFileLeaf { FullPath = myFile }; var mutant = new Mutant(); // Act var filterResult = target.FilterMutants(new List <Mutant>() { mutant }, file.ToReadOnly(), options); // Assert filterResult.ShouldContain(mutant); }
public void ShouldOnlyMutateChangedFiles() { var options = new StrykerOptions(diff: true); var diffProvider = new Mock <IDiffProvider>(MockBehavior.Strict); string myFile = Path.Combine("C:/test/", "myfile.cs");; diffProvider.Setup(x => x.ScanDiff()).Returns(new DiffResult() { ChangedFiles = new Collection <string>() { myFile } }); var target = new DiffMutantFilter(options, diffProvider.Object); var file = new FileLeaf { FullPath = myFile }; var mutant = new Mutant(); var filterResult = target.FilterMutants(new List <Mutant>() { mutant }, file, options); filterResult.ShouldContain(mutant); }
public void ShouldNotMutateUnchangedFiles() { var options = new StrykerOptions(diff: true); var dashboardClient = new Mock <IDashboardClient>(); var diffProvider = new Mock <IDiffProvider>(MockBehavior.Loose); var branchProvider = new Mock <IGitInfoProvider>(); string myFile = Path.Combine("C:/test/", "myfile.cs");; diffProvider.Setup(x => x.ScanDiff()).Returns(new DiffResult() { ChangedFiles = new Collection <string>() }); var target = new DiffMutantFilter(options, diffProvider.Object, dashboardClient.Object, branchProvider.Object); var file = new FileLeaf { FullPath = myFile }; var mutant = new Mutant(); var filterResult = target.FilterMutants(new List <Mutant>() { mutant }, file, options); filterResult.ShouldBeEmpty(); }
public void ShouldMutateAllFilesWhenATestHasBeenChanged() { string testProjectPath = "C:/MyTests"; var options = new StrykerOptions(diff: false); var diffProvider = new Mock <IDiffProvider>(MockBehavior.Strict); // If a file inside the test project is changed, a test has been changed string myTest = Path.Combine(testProjectPath, "myTest.cs");; diffProvider.Setup(x => x.ScanDiff()).Returns(new DiffResult() { ChangedFiles = new Collection <string>() { myTest } }); var target = new DiffMutantFilter(options, diffProvider.Object); // check the diff result for a file not inside the test project var file = new FileLeaf { FullPath = Path.Combine("C:/NotMyTests", "myfile.cs") }; var mutant = new Mutant(); var filterResult = target.FilterMutants(new List <Mutant>() { mutant }, file, options); filterResult.ShouldContain(mutant); }
public void Should_ReturnAllMutants_When_NonSourceCodeFile_In_Tests_Has_Changed() { // Arrange var options = new StrykerOptions(compareToDashboard: true, projectVersion: "version"); var diffProviderMock = new Mock <IDiffProvider>(); var diffResult = new DiffResult() { ChangedTestFiles = new List <string> { "config.json" } }; diffProviderMock.Setup(x => x.ScanDiff()).Returns(diffResult); var target = new DiffMutantFilter(diffProviderMock.Object); var mutants = new List <Mutant> { new Mutant(), new Mutant(), new Mutant() }; // Act var result = target.FilterMutants(mutants, new CsharpFileLeaf() { FullPath = "C:\\Foo\\Bar" }.ToReadOnly(), options); // Assert result.ShouldBe(mutants); }
public void Should_IgnoreMutants_WithoutCoveringTestsInfo_When_Tests_Have_Changed() { // Arrange var diffProvider = new Mock <IDiffProvider>(MockBehavior.Loose); var options = new StrykerOptions(compareToDashboard: false, projectVersion: "version"); diffProvider.Setup(x => x.ScanDiff()).Returns(new DiffResult { ChangedSourceFiles = new List <string>(), ChangedTestFiles = new List <string> { "C:/testfile.cs" } }); var target = new DiffMutantFilter(diffProvider.Object); var mutants = new List <Mutant> { new Mutant() }; // Act var results = target.FilterMutants(mutants, new CsharpFileLeaf().ToReadOnly(), options); // Assert results.ShouldBeEmpty(); }
public void FilterMutantsReturnAllMutantsWhenCompareToDashboardEnabledAndBaselineNotAvailabe() { // Arrange var baselineProvider = new Mock <IBaselineProvider>(); var diffProvider = new Mock <IDiffProvider>(MockBehavior.Loose); var branchProvider = new Mock <IGitInfoProvider>(); var options = new StrykerOptions(compareToDashboard: true, projectVersion: "version"); var target = new DiffMutantFilter(options, diffProvider.Object, baselineProvider.Object, branchProvider.Object); var file = new Mock <ReadOnlyFileLeaf>(new CsharpFileLeaf()); var mutants = new List <Mutant> { new Mutant(), new Mutant(), new Mutant() }; // Act var results = target.FilterMutants(mutants, file.Object, options); // Assert results.Count().ShouldBe(3); }
public void FilterMutants_FiltersNoMutants_IfTestsChanged() { // Arrange var baselineProvider = new Mock <IBaselineProvider>(); baselineProvider.Setup(x => x.Load(It.IsAny <string>()) ).Returns( Task.FromResult( JsonReport.Build(new StrykerOptions(), JsonReportTestHelper.CreateProjectWith().ToReadOnlyInputComponent()) )); var diffProvider = new Mock <IDiffProvider>(MockBehavior.Loose); var gitInfoProvider = new Mock <IGitInfoProvider>(); var options = new StrykerOptions(compareToDashboard: false, projectVersion: "version"); diffProvider.Setup(x => x.ScanDiff()).Returns(new DiffResult { ChangedSourceFiles = new List <string>(), ChangedTestFiles = new List <string> { "C:/testfile1.cs" } }); var target = new DiffMutantFilter(options, diffProvider.Object, baselineProvider.Object, gitInfoProvider.Object); var testFile1 = new TestListDescription(new[] { new TestDescription(Guid.NewGuid().ToString(), "name1", "C:/testfile1.cs") }); var testFile2 = new TestListDescription(new[] { new TestDescription(Guid.NewGuid().ToString(), "name2", "C:/testfile2.cs") }); var expectedToStay1 = new Mutant { CoveringTests = testFile1 }; var expectedToStay2 = new Mutant { CoveringTests = testFile1 }; var mutants = new List <Mutant> { expectedToStay1, expectedToStay2, new Mutant { CoveringTests = testFile2 } }; // Act var results = target.FilterMutants(mutants, new CsharpFileLeaf().ToReadOnly(), options); // Assert results.ShouldBe(new [] { expectedToStay1, expectedToStay2 }); }
public void FilterMutants_FiltersNoMutants_IfTestsChanged() { // Arrange var baselineProvider = new Mock <IBaselineProvider>(); baselineProvider.Setup(x => x.Load(It.IsAny <string>()) ).Returns( Task.FromResult( JsonReport.Build(new StrykerOptions(), JsonReportTestHelper.CreateProjectWith()) )); var diffProvider = new Mock <IDiffProvider>(MockBehavior.Loose); var gitInfoProvider = new Mock <IGitInfoProvider>(); var options = new StrykerOptions(compareToDashboard: false, projectVersion: "version"); diffProvider.Setup(x => x.ScanDiff()).Returns(new DiffResult { ChangedFiles = new List <string>(), TestFilesChanged = new List <string> { "C:/testfile.cs" } }); var target = new DiffMutantFilter(options, diffProvider.Object, baselineProvider.Object, gitInfoProvider.Object); var testDescriptions = new List <TestDescription> { new TestDescription(Guid.NewGuid().ToString(), "name", "C:/testfile.cs") }; var testListDescription = new TestListDescription(testDescriptions); var mutants = new List <Mutant> { new Mutant { CoveringTests = testListDescription }, new Mutant(), new Mutant() }; // Act var results = target.FilterMutants(mutants, new FileLeaf(), options); // Assert results.Count().ShouldBe(1); }
public void FilterMutantsWithNoChangedFilesAndNoCoverage() { // Arrange var diffProvider = new Mock <IDiffProvider>(MockBehavior.Strict); var options = new StrykerOptions(); diffProvider.Setup(x => x.ScanDiff()).Returns(new DiffResult { ChangedSourceFiles = new List <string>() }); var target = new DiffMutantFilter(diffProvider.Object); var mutants = new List <Mutant> { new Mutant() { Id = 1, Mutation = new Mutation(), ResultStatus = MutantStatus.NoCoverage }, new Mutant() { Id = 2, Mutation = new Mutation(), ResultStatus = MutantStatus.NoCoverage }, new Mutant() { Id = 3, Mutation = new Mutation(), ResultStatus = MutantStatus.NoCoverage } }; // Act var results = target.FilterMutants(mutants, new CsharpFileLeaf() { RelativePath = "src/1/SomeFile0.cs" }.ToReadOnly(), options); // Assert results.Count().ShouldBe(0); mutants.ShouldAllBe(m => m.ResultStatus == MutantStatus.Ignored); mutants.ShouldAllBe(m => m.ResultStatusReason == "Mutant not changed compared to target commit"); }
public void FilterMutantsForStatusNotRunReturnsAllMutantsWithStatusNotRun() { // Arrange var dashboardClient = new Mock <IDashboardClient>(); dashboardClient.Setup(x => x.PullReport(It.IsAny <string>()) ).Returns( Task.FromResult( JsonReport.Build(new StrykerOptions(), JsonReportTestHelper.CreateProjectWith()) )); var diffProvider = new Mock <IDiffProvider>(MockBehavior.Loose); var branchProvider = new Mock <IGitInfoProvider>(); var options = new StrykerOptions(compareToDashboard: true, projectVersion: "version"); diffProvider.Setup(x => x.ScanDiff()).Returns(new DiffResult { TestsChanged = false, ChangedFiles = new List <string>() }); var target = new DiffMutantFilter(options, diffProvider.Object, dashboardClient.Object, branchProvider.Object); var mutants = new List <Mutant> { new Mutant() { ResultStatus = MutantStatus.NotRun }, new Mutant() { ResultStatus = MutantStatus.NotRun }, new Mutant() { ResultStatus = MutantStatus.Killed } }; var results = target.FilterMutants(mutants, new FileLeaf(), options); results.Count().ShouldBe(2); }
public void ShouldNotFilterMutantsWhereCoveringTestsContainsChangedTestFile() { // Arrange string testProjectPath = "C:/MyTests"; var options = new StrykerOptions(); var baselineProvider = new Mock <IBaselineProvider>(); var diffProvider = new Mock <IDiffProvider>(MockBehavior.Loose); var branchProvider = new Mock <IGitInfoProvider>(); // If a file inside the test project is changed, a test has been changed string myTest = Path.Combine(testProjectPath, "myTest.cs");; diffProvider.Setup(x => x.ScanDiff()).Returns(new DiffResult() { ChangedSourceFiles = new Collection <string>() { myTest }, ChangedTestFiles = new Collection <string>() { myTest } }); var target = new DiffMutantFilter(options, diffProvider.Object, baselineProvider.Object, branchProvider.Object); // check the diff result for a file not inside the test project var file = new CsharpFileLeaf { FullPath = Path.Combine("C:/NotMyTests", "myfile.cs") }; var mutant = new Mutant(); mutant.CoveringTests.Add(new TestDescription(Guid.NewGuid().ToString(), "name", myTest)); // Act var filterResult = target.FilterMutants(new List <Mutant>() { mutant }, file.ToReadOnly(), options); // Assert filterResult.ShouldContain(mutant); }
public void FilterMutants_FiltersNoMutants_IfTestsChanged() { // Arrange var diffProvider = new Mock <IDiffProvider>(MockBehavior.Loose); var options = new StrykerOptions(compareToDashboard: false, projectVersion: "version"); diffProvider.Setup(x => x.ScanDiff()).Returns(new DiffResult { ChangedSourceFiles = new List <string>(), ChangedTestFiles = new List <string> { "C:/testfile1.cs" } }); var target = new DiffMutantFilter(diffProvider.Object); var testFile1 = new TestListDescription(new[] { new TestDescription(Guid.NewGuid().ToString(), "name1", "C:/testfile1.cs") }); var testFile2 = new TestListDescription(new[] { new TestDescription(Guid.NewGuid().ToString(), "name2", "C:/testfile2.cs") }); var expectedToStay1 = new Mutant { CoveringTests = testFile1 }; var expectedToStay2 = new Mutant { CoveringTests = testFile1 }; var mutants = new List <Mutant> { expectedToStay1, expectedToStay2, new Mutant { CoveringTests = testFile2 } }; // Act var results = target.FilterMutants(mutants, new CsharpFileLeaf().ToReadOnly(), options); // Assert results.ShouldBe(new [] { expectedToStay1, expectedToStay2 }); }
public void Should_ReturnAllMutants_When_NonSourceCodeFile_In_Tests_Has_Changed() { // Arrange var options = new StrykerOptions(compareToDashboard: true, projectVersion: "version"); var diffProviderMock = new Mock <IDiffProvider>(); var baselineProviderMock = new Mock <IBaselineProvider>(); var gitInfoProviderMock = new Mock <IGitInfoProvider>(MockBehavior.Loose); var diffResult = new DiffResult() { ChangedTestFiles = new List <string> { "config.json" } }; diffProviderMock.Setup(x => x.ScanDiff()).Returns(diffResult); baselineProviderMock.Setup(x => x.Load(It.IsAny <string>()) ).Returns( Task.FromResult( JsonReport.Build(new StrykerOptions(), JsonReportTestHelper.CreateProjectWith().ToReadOnlyInputComponent()) )); var target = new DiffMutantFilter(options, diffProviderMock.Object, baselineProviderMock.Object, gitInfoProviderMock.Object); var mutants = new List <Mutant> { new Mutant(), new Mutant(), new Mutant() }; // Act var result = target.FilterMutants(mutants, new CsharpFileLeaf() { FullPath = "C:\\Foo\\Bar" }.ToReadOnly(), options); // Assert result.ShouldBe(mutants); }
public void Should_IgnoreMutants_WithoutCoveringTestsInfo_When_Tests_Have_Changed() { // Arrange var baselineProvider = new Mock <IBaselineProvider>(); baselineProvider.Setup(x => x.Load(It.IsAny <string>()) ).Returns( Task.FromResult( JsonReport.Build(new StrykerOptions(), JsonReportTestHelper.CreateProjectWith().ToReadOnlyInputComponent()) )); var diffProvider = new Mock <IDiffProvider>(MockBehavior.Loose); var gitInfoProvider = new Mock <IGitInfoProvider>(); var options = new StrykerOptions(compareToDashboard: false, projectVersion: "version"); diffProvider.Setup(x => x.ScanDiff()).Returns(new DiffResult { ChangedSourceFiles = new List <string>(), ChangedTestFiles = new List <string> { "C:/testfile.cs" } }); var target = new DiffMutantFilter(options, diffProvider.Object, baselineProvider.Object, gitInfoProvider.Object); var mutants = new List <Mutant> { new Mutant() }; // Act var results = target.FilterMutants(mutants, new CsharpFileLeaf().ToReadOnly(), options); // Assert results.ShouldBeEmpty(); }
public void FilterMutantsFiltersAll_WhenNoTestsChanged_CompareToDashboardDisabled_AndFileNotCahnged() { // Arrange var baselineProvider = new Mock <IBaselineProvider>(); baselineProvider.Setup(x => x.Load(It.IsAny <string>()) ).Returns( Task.FromResult( JsonReport.Build(new StrykerOptions(), JsonReportTestHelper.CreateProjectWith()) )); var diffProvider = new Mock <IDiffProvider>(MockBehavior.Loose); var branchProvider = new Mock <IGitInfoProvider>(); var options = new StrykerOptions(compareToDashboard: false, projectVersion: "version"); diffProvider.Setup(x => x.ScanDiff()).Returns(new DiffResult { ChangedFiles = new List <string>(), }); var target = new DiffMutantFilter(options, diffProvider.Object, baselineProvider.Object, branchProvider.Object); var mutants = new List <Mutant> { new Mutant(), new Mutant(), new Mutant() }; // Act var results = target.FilterMutants(mutants, new FileLeaf(), options); // Assert results.Count().ShouldBe(0); }
public void FilterMutantsForStatusNotRunReturnsAllMutantsWithStatusNotRun() { // Arrange var baselineProvider = new Mock <IBaselineProvider>(); baselineProvider.Setup(x => x.Load(It.IsAny <string>())).ReturnsAsync(JsonReport.Build(new StrykerOptions(), JsonReportTestHelper.CreateProjectWith())); var diffProvider = new Mock <IDiffProvider>(MockBehavior.Loose); var branchProvider = new Mock <IGitInfoProvider>(); var options = new StrykerOptions(compareToDashboard: true, projectVersion: "version"); diffProvider.Setup(x => x.ScanDiff()).Returns(new DiffResult { ChangedFiles = new List <string>() }); var target = new DiffMutantFilter(options, diffProvider.Object, baselineProvider.Object, branchProvider.Object); var tree = CSharpSyntaxTree.ParseText("void M(){ int i = 0 + 8; }"); var originalNode = tree.GetRoot().DescendantNodes().OfType <BinaryExpressionSyntax>().First(); var mutation = new Mutation() { OriginalNode = originalNode, ReplacementNode = SyntaxFactory.BinaryExpression(SyntaxKind.SubtractExpression, originalNode.Left, originalNode.Right), DisplayName = "This name should display", Type = Mutator.Arithmetic }; var mutants = new List <Mutant> { new Mutant() { Id = 1, ResultStatus = MutantStatus.NotRun, Mutation = mutation }, new Mutant() { Id = 2, ResultStatus = MutantStatus.NotRun, Mutation = mutation }, new Mutant() { Id = 3, ResultStatus = MutantStatus.Killed, Mutation = mutation } }; // Act var results = target.FilterMutants(mutants, new FileLeaf() { RelativePath = "src/1/SomeFile0.cs" }, options); // Assert results.Count().ShouldBe(3); }