public void RapportComponent_ShouldCalculateMutationScore_OnlyKilledIsSuccessful(MutantStatus status, decimal expectedScore)
        {
            var target = new FolderComposite()
            {
                Name = "RootFolder"
            };
            var subFolder = new FolderComposite()
            {
                Name = "SubFolder"
            };

            target.Add(new FileLeaf()
            {
                Mutants = new Collection <Mutant>()
                {
                    new Mutant()
                    {
                        ResultStatus = status
                    }
                }
            });

            var result = target.GetMutationScore();

            result.ShouldBe(expectedScore);
        }
Beispiel #2
0
        public void ReportComponent_ShouldCalculateMutationScore_OnlyKilledIsSuccessful(MutantStatus status, double expectedScore)
        {
            var target = new CsharpFolderComposite();

            target.Add(new CsharpFileLeaf()
            {
                Mutants = new Collection <Mutant>()
                {
                    new Mutant()
                    {
                        ResultStatus = status
                    }
                }
            });

            var result = target.GetMutationScore();

            result.ShouldBe(expectedScore);
        }
        public void ShouldThrowExceptionWhenOtherStatusThanNotRunIsPassed(MutantStatus status)
        {
            var mutant = new Mutant {
                Id = 1, ResultStatus = status
            };
            var basePath = Path.Combine(FilesystemRoot, "ExampleProject.Test");

            var folder = new FolderComposite()
            {
                Name = "ProjectRoot"
            };

            folder.Add(new FileLeaf()
            {
                Name    = "SomeFile.cs",
                Mutants = new Collection <Mutant>()
                {
                    mutant
                }
            });

            var input = new MutationTestInput()
            {
                ProjectInfo = new ProjectInfo()
                {
                    ProjectUnderTestAnalyzerResult = TestHelper.SetupProjectAnalyzerResult(properties: new Dictionary <string, string>()
                    {
                        { "TargetDir", "/bin/Debug/netcoreapp2.1" },
                        { "TargetFileName", "TestName.dll" }
                    }).Object,
                    TestProjectAnalyzerResults = new List <IAnalyzerResult> {
                        TestHelper.SetupProjectAnalyzerResult(properties: new Dictionary <string, string>()
                        {
                            { "TargetDir", "/bin/Debug/netcoreapp2.1" },
                            { "TargetFileName", "TestName.dll" }
                        }).Object
                    },
                    ProjectContents = folder
                },
                AssemblyReferences = new ReferenceProvider().GetReferencedAssemblies()
            };
            var reporterMock = new Mock <IReporter>(MockBehavior.Strict);

            reporterMock.Setup(x => x.OnMutantTested(It.IsAny <Mutant>()));

            var runnerMock = new Mock <ITestRunner>();

            runnerMock.Setup(x => x.DiscoverNumberOfTests()).Returns(1);
            var executorMock = new Mock <IMutationTestExecutor>(MockBehavior.Strict);

            executorMock.SetupGet(x => x.TestRunner).Returns(runnerMock.Object);
            executorMock.Setup(x => x.Test(It.IsAny <IList <Mutant> >(), It.IsAny <int>(), It.IsAny <TestUpdateHandler>()));

            var mutantFilterMock = new Mock <IMutantFilter>(MockBehavior.Loose);

            var options = new StrykerOptions(basePath: basePath, fileSystem: new MockFileSystem());

            var target = new MutationTestProcess(input,
                                                 reporterMock.Object,
                                                 executorMock.Object,
                                                 mutantFilter: mutantFilterMock.Object,
                                                 options: options);

            Should.Throw <GeneralStrykerException>(() => target.Test(input.ProjectInfo.ProjectContents.Mutants));
        }
        public void ReportRunTest_ShouldReportTestProgressAs50PercentageDone_And_FirstTestExecutionTime_WhenHalfOfTestsAreDone(MutantStatus status)
        {
            var progressBarMock = new Mock <IProgressBar>(MockBehavior.Strict);

            progressBarMock.Setup(x => x.Start(It.IsAny <int>(), It.IsAny <string>()));
            progressBarMock.Setup(x => x.Tick(It.IsAny <string>()));

            var progressBarReporter = new ProgressBarReporter(progressBarMock.Object, new FixedClock());

            var mutantTestResult = new Mutant()
            {
                ResultStatus = status
            };

            progressBarReporter.ReportInitialState(2);
            progressBarReporter.ReportRunTest(mutantTestResult);

            string expected = string.Empty;

            switch (status)
            {
            case MutantStatus.Killed:
                expected = "│ Testing mutant 1 / 2 │ K 1 │ S 0 │ T 0 │ ~0m 00s │";
                break;

            case MutantStatus.Survived:
                expected = "│ Testing mutant 1 / 2 │ K 0 │ S 1 │ T 0 │ ~0m 00s │";
                break;

            case MutantStatus.Timeout:
                expected = "│ Testing mutant 1 / 2 │ K 0 │ S 0 │ T 1 │ ~0m 00s │";
                break;
            }

            progressBarMock.Verify(x => x.Tick(
                                       It.Is <string>(b => b == expected)
                                       ));
        }