コード例 #1
0
        public void JsonReportFileComponent_ShouldHaveLanguageSetToCs()
        {
            var folderComponent = JsonReportTestHelper.CreateProjectWith();
            var fileComponent   = (folderComponent as FolderComposite).GetAllFiles().First();

            new JsonReportFileComponent(fileComponent).Language.ShouldBe("cs");
        }
コード例 #2
0
        public void ShouldUploadHumanReadableWhenCompareToDashboardEnabled()
        {
            // Arrange
            var reporters = new string[1];

            reporters[0] = "dashboard";

            var options = new StrykerOptions(
                dashboardApiKey: "Acces_Token",
                projectName: "github.com/JohnDoe/project",
                projectVersion: "version/human/readable",
                reporters: reporters
                );

            var dashboardClientMock = new Mock <IDashboardClient>();

            dashboardClientMock.Setup(x => x.PublishReport(It.IsAny <string>(), "version/human/readable"));
            var branchProviderMock = new Mock <IGitInfoProvider>();

            var target = new DashboardReporter(options, dashboardClient: dashboardClientMock.Object);

            // Act
            target.OnAllMutantsTested(JsonReportTestHelper.CreateProjectWith().ToReadOnlyInputComponent());

            // Assert
            dashboardClientMock.Verify(x => x.PublishReport(It.IsAny <string>(), "version/human/readable"), Times.Once);
        }
コード例 #3
0
        public void ShouldNotOpenDashboardReportIfOptionIsProvided(ReportType?reportType)
        {
            var reporters = new[] { Reporter.Dashboard };
            var options   = new StrykerOptions
            {
                ReportTypeToOpen = reportType,
                DashboardApiKey  = "Access_Token",
                ProjectName      = "github.com/JohnDoe/project",
                ProjectVersion   = "version/human/readable",
                Reporters        = reporters
            };
            var mockProcess         = new Mock <IWebbrowserOpener>();
            var dashboardClientMock = new Mock <IDashboardClient>();

            dashboardClientMock.Setup(x => x.PublishReport(It.IsAny <JsonReport>(), "version/human/readable"))
            .Returns(Task.FromResult("https://dashboard.com"));

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

            reporter.OnAllMutantsTested(mutationTree);

            // Check if browser open action is invoked
            mockProcess.VerifyNoOtherCalls();
        }
コード例 #4
0
        public void LogsDebugWhenBaselineUploadedSuccesfull()
        {
            // Arrange
            var reporters = new string[1];

            reporters[0] = "dashboard";

            var options = new StrykerOptions(
                compareToDashboard: true,
                dashboardApiKey: "Acces_Token",
                projectName: "github.com/JohnDoe/project",
                projectVersion: "version/human/readable",
                reporters: reporters)
            {
            };
            var loggerMock          = new Mock <ILogger <DashboardReporter> >(MockBehavior.Loose);
            var dashboardClientMock = new Mock <IDashboardClient>(MockBehavior.Loose);
            var branchProviderMock  = new Mock <IGitInfoProvider>();
            var chalkMock           = new Mock <IChalk>();

            branchProviderMock.Setup(x => x.GetCurrentBranchName()).Returns("refs/heads/master");
            dashboardClientMock.Setup(x => x.PublishReport(It.IsAny <string>(), "dashboard-compare/refs/heads/master")).ReturnsAsync("http://www.example.com/baseline");
            dashboardClientMock.Setup(x => x.PublishReport(It.IsAny <string>(), "version/human/readable")).ReturnsAsync("http://www.example.com/humanreadable");
            var target = new DashboardReporter(options, dashboardClient: dashboardClientMock.Object, branchProvider: branchProviderMock.Object, loggerMock.Object, chalkMock.Object);

            // Act
            target.OnAllMutantsTested(JsonReportTestHelper.CreateProjectWith());

            // Assert
            loggerMock.Verify(x => x.Log(LogLevel.Debug, It.IsAny <EventId>(), It.Is <It.IsAnyType>((v, t) => true), It.IsAny <Exception>(), It.Is <Func <It.IsAnyType, Exception, string> >((v, t) => true)));
            chalkMock.Verify(x => x.Green(It.Is <string>(s => s == "Your stryker report has been uploaded to: \n http://www.example.com/humanreadable \nYou can open it in your browser of choice.")));
        }
コード例 #5
0
        public void ShouldCallUploadBaselineAndHumanReadableWhenCompareToDashboardEnabled()
        {
            // Arrange
            var reporters = new string[1];

            reporters[0] = "dashboard";

            var options = new StrykerOptions(
                compareToDashboard: true,
                dashboardApiKey: "Acces_Token",
                projectName: "github.com/JohnDoe/project",
                projectVersion: "version/human/readable",
                reporters: reporters)
            {
            };

            var dashboardClientMock = new Mock <IDashboardClient>(MockBehavior.Loose);
            var branchProviderMock  = new Mock <IGitInfoProvider>();

            branchProviderMock.Setup(x => x.GetCurrentBranchName()).Returns("refs/heads/master");
            var target = new DashboardReporter(options, dashboardClient: dashboardClientMock.Object, branchProvider: branchProviderMock.Object);

            // Act
            target.OnAllMutantsTested(JsonReportTestHelper.CreateProjectWith());

            // Assert
            dashboardClientMock.Verify(x => x.PublishReport(It.IsAny <string>(), "dashboard-compare/refs/heads/master"), Times.Once);
            dashboardClientMock.Verify(x => x.PublishReport(It.IsAny <string>(), "version/human/readable"), Times.Once);
        }
コード例 #6
0
        public void JsonReportFileComponent_ShouldContainOriginalSource()
        {
            var folderComponent = JsonReportTestHelper.CreateProjectWith();
            var fileComponent   = (folderComponent as FolderComposite).GetAllFiles().First();

            new JsonReportFileComponent(fileComponent).Source.ShouldBe(fileComponent.SourceCode);
        }
コード例 #7
0
        public void ShouldUploadHumanReadableWhenCompareToDashboardEnabled()
        {
            // Arrange
            var reporters = new[] { Reporter.Dashboard };

            var options = new StrykerOptions {
                DashboardApiKey = "Access_Token",
                ProjectName     = "github.com/JohnDoe/project",
                ProjectVersion  = "version/human/readable",
                Reporters       = reporters
            };

            var mockProcess         = new Mock <IWebbrowserOpener>();
            var dashboardClientMock = new Mock <IDashboardClient>();

            dashboardClientMock.Setup(x => x.PublishReport(It.IsAny <JsonReport>(), "version/human/readable"));
            var branchProviderMock = new Mock <IGitInfoProvider>();

            var target = new DashboardReporter(options, dashboardClient: dashboardClientMock.Object, processWrapper: mockProcess.Object);

            // Act
            target.OnAllMutantsTested(JsonReportTestHelper.CreateProjectWith());

            // Assert
            dashboardClientMock.Verify(x => x.PublishReport(It.IsAny <JsonReport>(), "version/human/readable"), Times.Once);
        }
コード例 #8
0
        public void JsonReport_WithMutationScoreOverThresholdHighHasGoodHealth()
        {
            var folderComponent = JsonReportTestHelper.CreateProjectWith();

            var report = JsonReport.Build(new StrykerOptions(thresholdHigh: 20, thresholdLow: 10), folderComponent);

            report.Files.First().Value.Health.ShouldBe(Health.Good);
        }
コード例 #9
0
        public void JsonReport_ShouldContainTheProjectRoot()
        {
            var folderComponent = JsonReportTestHelper.CreateProjectWith();

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

            report.ProjectRoot.ShouldBe("/home/user/src/project/");
        }
コード例 #10
0
        public void JsonReport_ShouldContainAtLeastOneFile()
        {
            var folderComponent = JsonReportTestHelper.CreateProjectWith();

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

            report.Files.Count.ShouldBeGreaterThan(0);
        }
コード例 #11
0
        public void JsonReport_WithMutationScoreUnderThresholdLowHasDangerHealth()
        {
            var folderComponent = JsonReportTestHelper.CreateProjectWith();

            var report = JsonReport.Build(new StrykerOptions(thresholdHigh: 80, thresholdLow: 67), folderComponent);

            report.Files.First().Value.Health.ShouldBe(Health.Danger);
        }
コード例 #12
0
        public void JsonReport_WithMutationScoreBetweenThresholdHighInclusiveAndLowNonInclusiveHasWarningHealth()
        {
            var folderComponent = JsonReportTestHelper.CreateProjectWith();

            var report = JsonReport.Build(new StrykerOptions(thresholdHigh: 67, thresholdLow: 66), folderComponent);

            report.Files.First().Value.Health.ShouldBe(Health.Warning);
        }
コード例 #13
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"));
        }
コード例 #14
0
        public void JsonReport_BuildReportReturnsSingletonJsonReport()
        {
            var folderComponent = JsonReportTestHelper.CreateProjectWith();
            var options         = new StrykerOptions();

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

            secondReport.ShouldBe(firstReport);
        }
コード例 #15
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.");
        }
コード例 #16
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());
                }
            }
        }
コード例 #17
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);
                }
            }
        }
コード例 #18
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);
        }
コード例 #19
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);
                }
            }
        }
コード例 #20
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##"));
        }
コード例 #21
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();
        }
コード例 #22
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.");
        }
コード例 #23
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");
        }
コード例 #24
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##");
        }
コード例 #25
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));
        }
コード例 #26
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");
        }