예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }
예제 #5
0
        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);
        }
예제 #6
0
        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[] { }));
        }
예제 #7
0
        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();
        }
예제 #8
0
        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)));
        }
예제 #9
0
        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")));
        }
예제 #10
0
        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")));
        }
예제 #11
0
        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();
        }
예제 #12
0
        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();
        }
예제 #13
0
        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);
        }
예제 #14
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>>()));
        }
예제 #15
0
        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>>()));
        }
예제 #16
0
        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();
        }
예제 #17
0
        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>>()));
        }
예제 #18
0
        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>>()));
        }
예제 #19
0
        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)));
        }
예제 #20
0
        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();
        }
예제 #21
0
        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>>()));
        }
예제 #22
0
        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)));
        }
예제 #23
0
        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)));
        }
예제 #24
0
        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>>()));
        }
예제 #25
0
        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>>()));
        }
예제 #26
0
        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>>()));
        }
예제 #27
0
        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")));
        }
예제 #28
0
        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> >()));
        }
예제 #29
0
        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>>()));
        }
예제 #30
0
        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);
        }