コード例 #1
0
        public void JsonReport_ThresholdsAreSet()
        {
            var folderComponent = JsonReportTestHelper.CreateProjectWith();

            var report = JsonReport.Build(new StrykerOptions(), folderComponent);

            report.ShouldSatisfyAllConditions(
                () => report.Thresholds.ShouldContainKey("high"),
                () => report.Thresholds.ShouldContainKey("low"));
        }
コード例 #2
0
        public void JsonReport_BuildReportReturnsSingletonJsonReport()
        {
            var folderComponent = JsonReportTestHelper.CreateProjectWith();
            var options         = new StrykerOptions();

            var firstReport  = JsonReport.Build(options, folderComponent.ToReadOnlyInputComponent());
            var secondReport = JsonReport.Build(options, folderComponent.ToReadOnlyInputComponent());

            secondReport.ShouldBe(firstReport);
        }
コード例 #3
0
        public void JsonReporter_OnAllMutantsTestedShouldWriteJsonToFile()
        {
            var mockFileSystem = new MockFileSystem();
            var options        = new StrykerOptions(thresholdBreak: 0, thresholdHigh: 80, thresholdLow: 60);
            var reporter       = new JsonReporter(options, mockFileSystem);

            reporter.OnAllMutantsTested(JsonReportTestHelper.CreateProjectWith());
            var reportPath = Path.Combine(options.OutputPath, "reports", $"mutation-report.json");

            mockFileSystem.FileExists(reportPath).ShouldBeTrue($"Path {reportPath} should exist but it does not.");
        }
コード例 #4
0
        public void JsonReportFileComponents_ShouldContainMutants()
        {
            var folderComponent = JsonReportTestHelper.CreateProjectWith();

            foreach (var file in (folderComponent as FolderComposite).GetAllFiles())
            {
                var jsonReportComponent = new JsonReportFileComponent(file);
                foreach (var mutant in file.Mutants)
                {
                    jsonReportComponent.Mutants.ShouldContain(m => m.Id == mutant.Id);
                }
            }
        }
コード例 #5
0
        public void JsonReportFileComponents_ShouldContainMutants()
        {
            var folderComponent = JsonReportTestHelper.CreateProjectWith();

            foreach (var file in (folderComponent as CsharpFolderComposite).GetAllFiles())
            {
                var jsonReportComponent = new JsonReportFileComponent(((CsharpFileLeaf)file).ToReadOnly());
                foreach (var mutant in file.Mutants)
                {
                    jsonReportComponent.Mutants.ShouldContain(m => m.Id == mutant.Id.ToString());
                }
            }
        }
コード例 #6
0
        public void JsonReporter_OnAllMutantsTestedShouldContainJsonReport()
        {
            var mockFileSystem = new MockFileSystem();
            var options        = new StrykerOptions(thresholdBreak: 0, thresholdHigh: 80, thresholdLow: 60);
            var reporter       = new HtmlReporter(options, mockFileSystem);

            reporter.OnAllMutantsTested(JsonReportTestHelper.CreateProjectWith().ToReadOnlyInputComponent());
            var reportPath = Path.Combine(options.OutputPath, "reports", $"mutation-report.html");

            var fileContents = mockFileSystem.GetFile(reportPath).TextContents;

            JsonReport.Build(options, null).ToJson().ShouldBeSubsetOf(fileContents);
        }
コード例 #7
0
        public void JsonReportFileComponent_DoesNotContainDuplicateMutants()
        {
            var loggerMock      = Mock.Of <ILogger>();
            var folderComponent = JsonReportTestHelper.CreateProjectWith(duplicateMutant: true);

            foreach (var file in (folderComponent as FolderComposite).GetAllFiles())
            {
                var jsonReportComponent = new JsonReportFileComponent(file, loggerMock);
                foreach (var mutant in file.Mutants)
                {
                    jsonReportComponent.Mutants.ShouldContain(m => m.Id == mutant.Id);
                }
            }
        }
コード例 #8
0
        public void JsonReporter_OnAllMutantsTestedShouldReplacePlaceholdersInHtmlFile()
        {
            var mockFileSystem = new MockFileSystem();
            var options        = new StrykerOptions(thresholdBreak: 0, thresholdHigh: 80, thresholdLow: 60);
            var reporter       = new HtmlReporter(options, mockFileSystem);

            reporter.OnAllMutantsTested(JsonReportTestHelper.CreateProjectWith().ToReadOnlyInputComponent());
            var reportPath = Path.Combine(options.OutputPath, "reports", $"mutation-report.html");

            var fileContents = mockFileSystem.GetFile(reportPath).TextContents;

            fileContents.ShouldSatisfyAllConditions(
                () => fileContents.ShouldNotContain("##REPORT_JS##"),
                () => fileContents.ShouldNotContain("##REPORT_TITLE##"),
                () => fileContents.ShouldNotContain("##REPORT_JSON##"));
        }
コード例 #9
0
        public void ShouldNotOpenHtmlReportIfOptionIsProvided(ReportType?reportType)
        {
            var mockProcess    = new Mock <IWebbrowserOpener>();
            var mockFileSystem = new MockFileSystem();
            var options        = new StrykerOptions
            {
                ReportTypeToOpen = reportType,
                OutputPath       = Directory.GetCurrentDirectory()
            };

            var reporter     = new HtmlReporter(options, mockFileSystem, processWrapper: mockProcess.Object);
            var mutationTree = JsonReportTestHelper.CreateProjectWith();

            reporter.OnAllMutantsTested(mutationTree);

            // Check if browser open action is invoked
            mockProcess.VerifyNoOtherCalls();
        }
コード例 #10
0
        public void ShouldWriteJsonToFile()
        {
            var mockProcess    = new Mock <IWebbrowserOpener>();
            var mockFileSystem = new MockFileSystem();
            var options        = new StrykerOptions
            {
                Thresholds = new Thresholds {
                    High = 80, Low = 60, Break = 0
                },
                OutputPath     = Directory.GetCurrentDirectory(),
                ReportFileName = "mutation-report"
            };
            var reporter = new HtmlReporter(options, mockFileSystem, processWrapper: mockProcess.Object);

            reporter.OnAllMutantsTested(JsonReportTestHelper.CreateProjectWith());
            var reportPath = Path.Combine(options.OutputPath, "reports", $"mutation-report.html");

            mockFileSystem.FileExists(reportPath).ShouldBeTrue($"Path {reportPath} should exist but it does not.");
        }
コード例 #11
0
        public void JsonReporter_OnAllMutantsTestedShouldWriteJsonToFile()
        {
            var mockFileSystem = new MockFileSystem();
            var options        = new StrykerOptions
            {
                Thresholds = new Thresholds {
                    High = 80, Low = 60, Break = 0
                },
                OutputPath     = Directory.GetCurrentDirectory(),
                ReportFileName = "mutation-report"
            };
            var reporter = new JsonReporter(options, mockFileSystem);

            reporter.OnAllMutantsTested(JsonReportTestHelper.CreateProjectWith());
            var reportPath = Path.Combine(options.OutputPath, "reports", $"mutation-report.json");

            mockFileSystem.FileExists(reportPath).ShouldBeTrue($"Path {reportPath} should exist but it does not.");
            var fileContents = mockFileSystem.File.ReadAllText(reportPath);

            fileContents.ShouldContain(@"""thresholds"":{");
            fileContents.ShouldContain(@"""high"":80");
            fileContents.ShouldContain(@"""low"":60");
        }
コード例 #12
0
        public void ShouldOpenHtmlReportIfOptionIsProvided()
        {
            var mockProcess    = new Mock <IWebbrowserOpener>();
            var mockFileSystem = new MockFileSystem();
            var options        = new StrykerOptions
            {
                ReportTypeToOpen = ReportType.Html,
                OutputPath       = Directory.GetCurrentDirectory(),
                ReportFileName   = "mutation-report"
            };

            var reporter     = new HtmlReporter(options, mockFileSystem, processWrapper: mockProcess.Object);
            var mutationTree = JsonReportTestHelper.CreateProjectWith();

            reporter.OnAllMutantsTested(mutationTree);
            var reportUri = Path.Combine(options.OutputPath, "reports", $"{options.ReportFileName}.html");

            reportUri = reportUri.Replace("\\", "/");
            reportUri = reportUri.StartsWith("/") ? reportUri : "/" + reportUri;

            // Check if browser open action is invoked
            mockProcess.Verify(m => m.Open("file://" + reportUri));
        }
コード例 #13
0
        public void ShouldReplacePlaceholdersInHtmlFile()
        {
            var mockProcess    = new Mock <IWebbrowserOpener>();
            var mockFileSystem = new MockFileSystem();
            var options        = new StrykerOptions
            {
                Thresholds = new Thresholds {
                    High = 80, Low = 60, Break = 0
                },
                OutputPath     = Directory.GetCurrentDirectory(),
                ReportFileName = "mutation-report"
            };
            var reporter = new HtmlReporter(options, mockFileSystem, processWrapper: mockProcess.Object);

            reporter.OnAllMutantsTested(JsonReportTestHelper.CreateProjectWith());
            var reportPath = Path.Combine(options.OutputPath, "reports", $"mutation-report.html");

            var fileContents = mockFileSystem.GetFile(reportPath).TextContents;

            fileContents.ShouldNotContain("##REPORT_JS##");
            fileContents.ShouldNotContain("##REPORT_TITLE##");
            fileContents.ShouldNotContain("##REPORT_JSON##");
        }
コード例 #14
0
        public void ShouldContainJsonInHtmlReportFile()
        {
            var mockProcess    = new Mock <IWebbrowserOpener>();
            var mockFileSystem = new MockFileSystem();
            var options        = new StrykerOptions
            {
                Thresholds = new Thresholds {
                    High = 80, Low = 60, Break = 0
                },
                OutputPath     = Directory.GetCurrentDirectory(),
                ReportFileName = "mutation-report"
            };
            var reporter     = new HtmlReporter(options, mockFileSystem, processWrapper: mockProcess.Object);
            var mutationTree = JsonReportTestHelper.CreateProjectWith();

            reporter.OnAllMutantsTested(mutationTree);
            var reportPath = Path.Combine(options.OutputPath, "reports", $"mutation-report.html");

            var fileContents = mockFileSystem.GetFile(reportPath).TextContents;

            fileContents.ShouldContain(@"""thresholds"":{");
            fileContents.ShouldContain(@"""high"":80");
            fileContents.ShouldContain(@"""low"":60");
        }