public void StrykerCLI_WithConfigFile_ShouldStartStrykerWithConfigFileOptions(string argName) { var fileToExclude = FilePathUtils.ConvertPathSeparators("./Recursive.cs"); StrykerOptions actualOptions = null; var runResults = new StrykerRunResult(new StrykerOptions(), 0.3M); var mock = new Mock <IStrykerRunner>(MockBehavior.Strict); mock.Setup(x => x.RunMutationTest(It.IsAny <StrykerOptions>())) .Callback <StrykerOptions>((c) => actualOptions = c) .Returns(runResults) .Verifiable(); var target = new StrykerCLI(mock.Object); target.Run(new string[] { argName, "filled-stryker-config.json" }); mock.VerifyAll(); actualOptions.AdditionalTimeoutMS.ShouldBe(9999); actualOptions.LogOptions.LogLevel.ShouldBe(LogEventLevel.Verbose); actualOptions.ProjectUnderTestNameFilter.ShouldBe("ExampleProject.csproj"); actualOptions.Reporters.ShouldHaveSingleItem(); actualOptions.Reporters.ShouldContain(Reporter.ConsoleReport); actualOptions.ConcurrentTestrunners.ShouldBe(1); actualOptions.Thresholds.Break.ShouldBe(20); actualOptions.Thresholds.Low.ShouldBe(30); actualOptions.Thresholds.High.ShouldBe(40); actualOptions.FilesToExclude.ShouldHaveSingleItem(); actualOptions.FilesToExclude.ShouldContain(fileToExclude); }
public void StrykerCLI_WithFilePatternSet_ShouldPassFilePatternSetToStryker(string argName) { var mock = new Mock <IStrykerRunner>(MockBehavior.Strict); StrykerOptions actualOptions = null; var runResults = new StrykerRunResult(new StrykerOptions(), 0.1); mock.Setup(x => x.RunMutationTest(It.IsAny <StrykerOptions>(), It.IsAny <IEnumerable <LogMessage> >())) .Callback <StrykerOptions, IEnumerable <LogMessage> >((c, m) => actualOptions = c) .Returns(runResults) .Verifiable(); var target = new StrykerCLI(mock.Object); target.Run(new[] { argName, @"['**/*Service.cs','!**/MySpecialService.cs', '**/MyOtherService.cs{1..10}{32..45}']" }); var firstFileToExclude = FilePattern.Parse("**/*Service.cs"); var secondFileToExclude = FilePattern.Parse("!**/MySpecialService.cs"); var thirdFileToExclude = FilePattern.Parse("**/MyOtherService.cs{1..10}{32..45}"); var filePatterns = actualOptions.FilePatterns.ToArray(); filePatterns.Length.ShouldBe(3); filePatterns.ShouldContain(firstFileToExclude); filePatterns.ShouldContain(secondFileToExclude); filePatterns.ShouldContain(thirdFileToExclude); }
public void StrykerCLI_WithFilesToExcludeSet_ShouldPassFilesToExcludeToStryker(string argName) { var mock = new Mock <IStrykerRunner>(MockBehavior.Strict); StrykerOptions actualOptions = null; var runResults = new StrykerRunResult(new StrykerOptions(), 0.1); mock.Setup(x => x.RunMutationTest(It.IsAny <StrykerOptions>(), It.IsAny <IEnumerable <LogMessage> >())) .Callback <StrykerOptions, IEnumerable <LogMessage> >((c, m) => actualOptions = c) .Returns(runResults) .Verifiable(); var target = new StrykerCLI(mock.Object); target.Run(new[] { argName, @"['./StartUp.cs','./ExampleDirectory/Recursive.cs', './ExampleDirectory/Recursive2.cs']" }); var firstFileToExclude = FilePattern.Parse("!StartUp.cs"); var secondFileToExclude = FilePattern.Parse("!ExampleDirectory/Recursive.cs"); var thirdFileToExclude = FilePattern.Parse("!ExampleDirectory/Recursive2.cs"); var filePatterns = actualOptions.FilePatterns.ToArray(); filePatterns.Count(x => x.IsExclude).ShouldBe(3); filePatterns.ShouldContain(firstFileToExclude); filePatterns.ShouldContain(secondFileToExclude); filePatterns.ShouldContain(thirdFileToExclude); }
public void StrykerCLI_WithFilesToExcludeSet_ShouldPassFilesToExcludeToStryker(string argName) { var mock = new Mock <IStrykerRunner>(MockBehavior.Strict); StrykerOptions actualOptions = null; StrykerRunResult runResults = new StrykerRunResult(new StrykerOptions(), 0.1M); mock.Setup(x => x.RunMutationTest(It.IsAny <StrykerOptions>())) .Callback <StrykerOptions>((c) => actualOptions = c) .Returns(runResults) .Verifiable(); var target = new StrykerCLI(mock.Object); target.Run(new[] { argName, @"['./StartUp.cs','./ExampleDirectory/Recursive.cs', '.\\ExampleDirectory/Recursive2.cs']" }); var firstFileToExclude = FilePathUtils.ConvertPathSeparators("./StartUp.cs"); var secondFileToExclude = FilePathUtils.ConvertPathSeparators("./ExampleDirectory/Recursive.cs"); var thirdFileToExclude = FilePathUtils.ConvertPathSeparators(@".\ExampleDirectory/Recursive2.cs"); var filesToExclude = actualOptions.FilesToExclude.ToArray(); filesToExclude.Length.ShouldBe(3); filesToExclude.ShouldContain(firstFileToExclude); filesToExclude.ShouldContain(secondFileToExclude); filesToExclude.ShouldContain(thirdFileToExclude); }
public void StrykerCLI_WithConfigFile_ShouldStartStrykerWithConfigFileOptions(string argName) { var filePattern = new FilePattern(Glob.Parse(FilePathUtils.NormalizePathSeparators("**/Test.cs")), true, new[] { TextSpan.FromBounds(1, 100), TextSpan.FromBounds(200, 300) }); StrykerOptions actualOptions = null; var runResults = new StrykerRunResult(new StrykerOptions(), 0.3); var mock = new Mock <IStrykerRunner>(MockBehavior.Strict); mock.Setup(x => x.RunMutationTest(It.IsAny <StrykerOptions>(), It.IsAny <IEnumerable <LogMessage> >())) .Callback <StrykerOptions, IEnumerable <LogMessage> >((c, m) => actualOptions = c) .Returns(runResults) .Verifiable(); var target = new StrykerCLI(mock.Object); target.Run(new string[] { argName, "filled-stryker-config.json" }); mock.VerifyAll(); actualOptions.DevMode.ShouldBe(true); actualOptions.AdditionalTimeoutMS.ShouldBe(9999); actualOptions.LogOptions.LogLevel.ShouldBe(LogEventLevel.Verbose); actualOptions.ProjectUnderTestNameFilter.ShouldBe("ExampleProject.csproj"); actualOptions.Reporters.ShouldHaveSingleItem(); actualOptions.Reporters.ShouldContain(Reporter.ConsoleReport); actualOptions.ConcurrentTestRunners.ShouldBe(1); actualOptions.Thresholds.Break.ShouldBe(20); actualOptions.Thresholds.Low.ShouldBe(30); actualOptions.Thresholds.High.ShouldBe(40); actualOptions.FilePatterns.Count().ShouldBe(2); actualOptions.FilePatterns.ShouldContain(filePattern); actualOptions.Optimizations.ShouldBe(OptimizationFlags.CoverageBasedTest | OptimizationFlags.AbortTestOnKill); }
public void StrykerCLI_OnException_ShouldThrow() { var mock = new Mock<IStrykerRunner>(MockBehavior.Strict); mock.Setup(x => x.RunMutationTest(It.IsAny<StrykerOptions>(), It.IsAny<IEnumerable<LogMessage>>())).Throws(new Exception("Initial testrun failed")).Verifiable(); var target = new StrykerCLI(mock.Object); Assert.Throws<Exception>(() => target.Run(new string[] { })); }
public void StrykerCLI_WithHelpArgument_ShouldNotStartStryker(string argName) { var mock = new Mock <IStrykerRunner>(MockBehavior.Strict); var target = new StrykerCLI(mock.Object); target.Run(new string[] { argName }); mock.VerifyNoOtherCalls(); }
public void StrykerCLI_WithLogFileArgument_ShouldPassLogFileArgumentsToStryker(string argName) { var mock = new Mock <IStrykerRunner>(MockBehavior.Strict); mock.Setup(x => x.RunMutationTest(It.IsAny <StrykerOptions>())); var target = new StrykerCLI(mock.Object); target.Run(new string[] { argName, "true" }); mock.Verify(x => x.RunMutationTest(It.Is <StrykerOptions>(o => o.LogOptions.LogToFile == true))); }
public void StrykerCLI_WithProjectArgument_ShouldPassProjectArgumentsToStryker(string argName) { var mock = new Mock <IStrykerRunner>(MockBehavior.Strict); mock.Setup(x => x.RunMutationTest(It.IsAny <StrykerOptions>())); var target = new StrykerCLI(mock.Object); target.Run(new string[] { argName, "SomeProjectName.csproj" }); mock.Verify(x => x.RunMutationTest(It.Is <StrykerOptions>(o => o.ProjectUnderTestNameFilter == "SomeProjectName.csproj"))); }
public void StrykerCLI_WithReporterArgument_ShouldPassReporterArgumentsToStryker(string argName) { var mock = new Mock <IStrykerRunner>(MockBehavior.Strict); mock.Setup(x => x.RunMutationTest(It.IsAny <StrykerOptions>())); var target = new StrykerCLI(mock.Object); target.Run(new string[] { argName, "Console" }); mock.Verify(x => x.RunMutationTest(It.Is <StrykerOptions>(o => o.Reporter == "Console"))); }
public void StrykerCLI_OnException_ShouldExit() { var mock = new Mock <IStrykerRunner>(MockBehavior.Strict); mock.Setup(x => x.RunMutationTest(It.IsAny <StrykerOptions>())).Throws(new Exception("Initial testrun failed")).Verifiable(); var target = new StrykerCLI(mock.Object); target.Run(new string[] { }); mock.VerifyAll(); }
public void StrykerCLI_ShouldStartStryker() { var mock = new Mock <IStrykerRunner>(MockBehavior.Strict); mock.Setup(x => x.RunMutationTest(It.IsAny <StrykerOptions>())).Verifiable(); var target = new StrykerCLI(mock.Object); target.Run(new string[] { }); mock.VerifyAll(); }
public void HappyFlowReturns0ExitCode() { string pathToExampleProject = Path.GetFullPath("../../../ExampleProject/ExampleProject.XUnit/"); Environment.CurrentDirectory = pathToExampleProject; var runner = new StrykerCLI(new StrykerRunner()); int exitCode = runner.Run(new string[] { "--log-console", "trace" }); exitCode.ShouldBe(0); }
public void StrykerCLI_WithCustomThresholdBreakParameter_ShouldPassThresholdBreakToStryker(string argName) { StrykerOptions options = new StrykerOptions(); var runResults = new StrykerRunResult(options, 0.3); var mock = new Mock<IStrykerRunner>(MockBehavior.Strict); mock.Setup(x => x.RunMutationTest(It.IsAny<StrykerOptions>(), It.IsAny<IEnumerable<LogMessage>>())).Returns(runResults); var target = new StrykerCLI(mock.Object); target.Run(new string[] { argName, "20" }); mock.Verify(x => x.RunMutationTest(It.Is<StrykerOptions>(o => o.Thresholds.Break == 20), It.IsAny<IEnumerable<LogMessage>>())); }
public void StrykerCLI_WithSolutionArgument_ShouldPassSolutionArgumentPlusBasePathToStryker(string argName) { StrykerOptions options = new StrykerOptions(); var runResults = new StrykerRunResult(options, 0.3); var mock = new Mock<IStrykerRunner>(MockBehavior.Strict); mock.Setup(x => x.RunMutationTest(It.IsAny<StrykerOptions>(), It.IsAny<IEnumerable<LogMessage>>())).Returns(runResults); var target = new StrykerCLI(mock.Object); target.Run(new string[] { argName, "SomeSolutionPath.sln" }); mock.Verify(x => x.RunMutationTest(It.Is<StrykerOptions>(o => o.SolutionPath.Contains("SomeSolutionPath.sln")), It.IsAny<IEnumerable<LogMessage>>())); }
public void StrykerCLI_WithNoArgumentsAndEmptyConfig_ShouldStartStrykerWithDefaultOptions() { var mock = new Mock <IStrykerRunner>(MockBehavior.Strict); StrykerOptions options = new StrykerOptions("", "Console", "", 1000, null, "trace", false, 1, 90, 80, 70); var runResults = new StrykerRunResult(options, 0.3M); mock.Setup(x => x.RunMutationTest(It.IsAny <StrykerOptions>())).Returns(runResults).Verifiable(); var target = new StrykerCLI(mock.Object); target.Run(new string[] { }); mock.VerifyAll(); }
public void StrykerCLI_WithTestProjectsArgument_ShouldPassTestProjectArgumentsToStryker(string argName) { StrykerOptions options = new StrykerOptions(); var runResults = new StrykerRunResult(options, 0.3); var mock = new Mock<IStrykerRunner>(MockBehavior.Strict); mock.Setup(x => x.RunMutationTest(It.IsAny<StrykerOptions>(), It.IsAny<IEnumerable<LogMessage>>())).Returns(runResults); var target = new StrykerCLI(mock.Object); target.Run(new string[] { argName, "['TestProjectFolder/SomeTestProjectName.csproj']" }); mock.Verify(x => x.RunMutationTest(It.Is<StrykerOptions>(o => o.TestProjects.Count() == 1), It.IsAny<IEnumerable<LogMessage>>())); }
public void StrykerCLI_WithLogLevelFileArgument_ShouldPassLogFileArgumentsToStryker(string argName) { StrykerOptions options = new StrykerOptions(); var runResults = new StrykerRunResult(options, 0.3); var mock = new Mock<IStrykerRunner>(MockBehavior.Strict); mock.Setup(x => x.RunMutationTest(It.IsAny<StrykerOptions>(), It.IsAny<IEnumerable<LogMessage>>())).Returns(runResults); var target = new StrykerCLI(mock.Object); target.Run(new string[] { argName }); mock.Verify(x => x.RunMutationTest(It.Is<StrykerOptions>(o => o.LogOptions.LogToFile), It.IsAny<IEnumerable<LogMessage>>())); }
public void StrykerCLI_WithCustomThresholdHighParameter_ShouldPassThresholdHighToStryker(string argName) { var mock = new Mock <IStrykerRunner>(MockBehavior.Strict); mock.Setup(x => x.RunMutationTest(It.IsAny <StrykerOptions>())); var target = new StrykerCLI(mock.Object); target.Run(new string[] { argName, "90" }); mock.Verify(x => x.RunMutationTest(It.Is <StrykerOptions>(o => o.ThresholdOptions.ThresholdHigh == 90))); }
public void StrykerCLI_WithNoArgumentsAndEmptyConfig_ShouldStartStrykerWithDefaultOptions() { var mock = new Mock <IStrykerRunner>(MockBehavior.Strict); var options = new StrykerOptions(); var runResults = new StrykerRunResult(options, 0.3); mock.Setup(x => x.RunMutationTest(It.IsAny <StrykerOptions>(), It.IsAny <IEnumerable <LogMessage> >())).Returns(runResults).Verifiable(); var target = new StrykerCLI(mock.Object); target.Run(new string[] { }); mock.VerifyAll(); }
public void StrykerCLI_WithProjectArgument_ShouldPassProjectArgumentsToStryker(string argName) { StrykerOptions options = new StrykerOptions(); var runResults = new StrykerRunResult(options, 0.3); var mock = new Mock<IStrykerRunner>(MockBehavior.Strict); mock.Setup(x => x.RunMutationTest(It.IsAny<StrykerOptions>(), It.IsAny<IEnumerable<LogMessage>>())).Returns(runResults); var target = new StrykerCLI(mock.Object); target.Run(new string[] { argName, "SomeProjectName.csproj" }); mock.Verify(x => x.RunMutationTest(It.Is<StrykerOptions>(o => o.ProjectUnderTestNameFilter == "SomeProjectName.csproj"), It.IsAny<IEnumerable<LogMessage>>())); }
public void StrykerCLI_WithMaxConcurrentTestrunnerArgument_ShouldPassMaxConcurrentTestrunnerToStryker(string argName) { var mock = new Mock <IStrykerRunner>(MockBehavior.Strict); mock.Setup(x => x.RunMutationTest(It.IsAny <StrykerOptions>())); var target = new StrykerCLI(mock.Object); target.Run(new string[] { argName, "4" }); mock.Verify(x => x.RunMutationTest(It.Is <StrykerOptions>(o => o.MaxConcurrentTestrunners == 4))); }
public void StrykerCLI_WithTimeoutArgument_ShouldPassTimeoutToStryker(string argName) { var mock = new Mock <IStrykerRunner>(MockBehavior.Strict); mock.Setup(x => x.RunMutationTest(It.IsAny <StrykerOptions>())); var target = new StrykerCLI(mock.Object); target.Run(new string[] { argName, "1000" }); mock.Verify(x => x.RunMutationTest(It.Is <StrykerOptions>(o => o.AdditionalTimeoutMS == 1000))); }
public void ShouldSetMutationLevelWhenPassed(string argName) { StrykerOptions options = new StrykerOptions(); var runResults = new StrykerRunResult(options, 0.3); var mock = new Mock<IStrykerRunner>(MockBehavior.Strict); mock.Setup(x => x.RunMutationTest(It.IsAny<StrykerOptions>(), It.IsAny<IEnumerable<LogMessage>>())).Returns(runResults); var target = new StrykerCLI(mock.Object); target.Run(new string[] { argName, "advanced" }); mock.Verify(x => x.RunMutationTest(It.Is<StrykerOptions>(o => o.MutationLevel == MutationLevel.Advanced), It.IsAny<IEnumerable<LogMessage>>())); }
public void StrykerCLI_WithReporterArgument_ShouldPassReporterArgumentsToStryker(string argName) { StrykerOptions options = new StrykerOptions(); var runResults = new StrykerRunResult(options, 0.3); var mock = new Mock<IStrykerRunner>(MockBehavior.Strict); mock.Setup(x => x.RunMutationTest(It.IsAny<StrykerOptions>(), It.IsAny<IEnumerable<LogMessage>>())).Returns(runResults); var target = new StrykerCLI(mock.Object); target.Run(new string[] { argName, $"['{ Reporter.ConsoleReport }', '{ Reporter.ConsoleProgressDots }']" }); mock.Verify(x => x.RunMutationTest(It.Is<StrykerOptions>(o => o.Reporters.Contains(Reporter.ConsoleReport) && o.Reporters.Contains(Reporter.ConsoleProgressDots)), It.IsAny<IEnumerable<LogMessage>>())); }
public void StrykerCLI_WithMaxConcurrentTestrunnerArgument_ShouldPassValidatedConcurrentTestrunnersToStryker(string argName) { StrykerOptions options = new StrykerOptions(); var runResults = new StrykerRunResult(options, 0.3); var mock = new Mock<IStrykerRunner>(MockBehavior.Strict); mock.Setup(x => x.RunMutationTest(It.IsAny<StrykerOptions>(), It.IsAny<IEnumerable<LogMessage>>())).Returns(runResults); var target = new StrykerCLI(mock.Object); target.Run(new string[] { argName, "4" }); mock.Verify(x => x.RunMutationTest(It.Is<StrykerOptions>(o => o.ConcurrentTestrunners <= 4), It.IsAny<IEnumerable<LogMessage>>())); }
public void StrykerCLI_WithTestProjectArgument_ShouldPassTestProjectArgumentsToStryker(string argName) { StrykerOptions options = new StrykerOptions(); var runResults = new StrykerRunResult(options, 0.3M); var mock = new Mock <IStrykerRunner>(MockBehavior.Strict); mock.Setup(x => x.RunMutationTest(It.IsAny <StrykerOptions>())).Returns(runResults); var target = new StrykerCLI(mock.Object); target.Run(new string[] { argName, "TestProjectFolder/SomeTestProjectName.csproj" }); mock.Verify(x => x.RunMutationTest(It.Is <StrykerOptions>(o => o.TestProjectNameFilter == "TestProjectFolder/SomeTestProjectName.csproj"))); }
public void StrykerCLI_WithNoFilesToExcludeSet_ShouldPassDefaultValueToStryker() { var mock = new Mock <IStrykerRunner>(MockBehavior.Strict); var options = new StrykerOptions(); var strykerRunResult = new StrykerRunResult(options, 0.1); mock.Setup(x => x.RunMutationTest(It.IsAny <StrykerOptions>(), It.IsAny <IEnumerable <LogMessage> >())).Returns(() => strykerRunResult); var target = new StrykerCLI(mock.Object); target.Run(new string[] { }); mock.Verify(x => x.RunMutationTest(It.Is <StrykerOptions>(o => o.FilePatterns.Count() == 1), It.IsAny <IEnumerable <LogMessage> >())); }
public void StrykerCLI_WithTimeoutArgument_ShouldPassTimeoutToStryker(string argName) { StrykerOptions options = new StrykerOptions(); var runResults = new StrykerRunResult(options, 0.3); var mock = new Mock<IStrykerRunner>(MockBehavior.Strict); mock.Setup(x => x.RunMutationTest(It.IsAny<StrykerOptions>(), It.IsAny<IEnumerable<LogMessage>>())).Returns(runResults); var target = new StrykerCLI(mock.Object); target.Run(new string[] { argName, "1000" }); mock.Verify(x => x.RunMutationTest(It.Is<StrykerOptions>(o => o.AdditionalTimeoutMS == 1000), It.IsAny<IEnumerable<LogMessage>>())); }
public void StrykerCLI_OnMutationScoreEqualToNullAndThresholdBreakAbove0_ShouldReturnExitCode0() { var mock = new Mock<IStrykerRunner>(MockBehavior.Strict); StrykerOptions options = new StrykerOptions(thresholdBreak: 40); StrykerRunResult strykerRunResult = new StrykerRunResult(options, double.NaN); mock.Setup(x => x.RunMutationTest(It.IsAny<StrykerOptions>(), It.IsAny<IEnumerable<LogMessage>>())).Returns(strykerRunResult).Verifiable(); var target = new StrykerCLI(mock.Object); int result = target.Run(new string[] { }); mock.Verify(); target.ExitCode.ShouldBe(0); result.ShouldBe(0); }