Esempio n. 1
0
        public void ShouldNotTest_WhenThereAreNoMutationsAtAll()
        {
            string basePath = Path.Combine(FilesystemRoot, "ExampleProject.Test");
            var    scenario = new FullRunScenario();
            var    folder   = new CsharpFolderComposite();

            folder.Add(new CsharpFileLeaf()
            {
                Mutants = scenario.GetMutants()
            });

            var projectUnderTest = TestHelper.SetupProjectAnalyzerResult(
                properties: new Dictionary <string, string>()
            {
                { "Language", "C#" }
            }).Object;
            var input = new MutationTestInput()
            {
                ProjectInfo = new ProjectInfo(new MockFileSystem())
                {
                    ProjectContents = folder,
                    ProjectUnderTestAnalyzerResult = projectUnderTest
                },
                AssemblyReferences = _assemblies
            };

            var executorMock = new Mock <IMutationTestExecutor>(MockBehavior.Strict);

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

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

            var options = new StrykerOptions()
            {
                BasePath = basePath
            };

            var reporterMock = new Mock <IReporter>(MockBehavior.Strict);

            reporterMock.Setup(x => x.OnMutantTested(It.IsAny <Mutant>()));
            var target = new MutationTestProcess(input,
                                                 reporterMock.Object,
                                                 executorMock.Object,
                                                 mutantFilter: mutantFilterMock.Object,
                                                 options: options);

            var testResult = target.Test(input.ProjectInfo.ProjectContents.Mutants);

            executorMock.Verify(x => x.Test(It.IsAny <IList <Mutant> >(), It.IsAny <ITimeoutValueCalculator>(), It.IsAny <TestUpdateHandler>()), Times.Never);
            reporterMock.Verify(x => x.OnStartMutantTestRun(It.IsAny <IList <Mutant> >()), Times.Never);
            reporterMock.Verify(x => x.OnMutantTested(It.IsAny <Mutant>()), Times.Never);
            testResult.MutationScore.ShouldBe(double.NaN);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }