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."); }
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"); }
public void JsonReporter_OnAllMutantsTestedShouldWriteJsonToFile() { var tree = CSharpSyntaxTree.ParseText("void M(){ int i = 0 + 8; }"); var originalNode = tree.GetRoot().DescendantNodes().OfType <BinaryExpressionSyntax>().First(); var mutation = new Mutation() { OriginalNode = originalNode, ReplacementNode = SyntaxFactory.BinaryExpression(SyntaxKind.SubtractExpression, originalNode.Left, originalNode.Right), DisplayName = "This name should display", Type = Mutator.Arithmetic }; var folder = new FolderComposite() { Name = "RootFolder" }; folder.Add(new FileLeaf() { Name = "SomeFile.cs", Mutants = new Collection <Mutant>() { new Mutant() { Id = 55, ResultStatus = MutantStatus.Killed, Mutation = mutation } }, SourceCode = "void M(){ int i = 0 + 8; }" }); folder.Add(new FileLeaf() { Name = "SomeOtherFile.cs", Mutants = new Collection <Mutant>() { new Mutant() { Id = 56, ResultStatus = MutantStatus.Survived, Mutation = mutation } }, SourceCode = "void M(){ int i = 0 + 8; }" }); folder.Add(new FileLeaf() { Name = "SomeOtherFile.cs", Mutants = new Collection <Mutant>() { new Mutant() { Id = 56, ResultStatus = MutantStatus.Skipped, Mutation = mutation } }, SourceCode = "void M(){ int i = 0 + 8; }" }); var mockFileSystem = new MockFileSystem(); var options = new StrykerOptions(thresholdBreak: 0, thresholdHigh: 80, thresholdLow: 60); var reporter = new JsonReporter(options, mockFileSystem); reporter.OnAllMutantsTested(folder); var reportPath = Path.Combine(options.BasePath, "StrykerOutput", "reports", $"mutation-report-{DateTime.Today.ToString("yyyy-MM-dd")}.json"); mockFileSystem.FileExists(reportPath).ShouldBeTrue($"Path {reportPath} should exist but it does not."); var reportObject = JsonConvert.DeserializeObject <JsonReporter.JsonReportComponent>(mockFileSystem.GetFile(reportPath).TextContents); reportObject.ThresholdHigh.ShouldBe(80); reportObject.ThresholdLow.ShouldBe(60); reportObject.ThresholdBreak.ShouldBe(0); ValidateJsonReportComponent(reportObject, folder, "Warning"); ValidateJsonReportComponent(reportObject.ChildResults.ElementAt(0), folder.Children.ElementAt(0), "Good", 1); ValidateJsonReportComponent(reportObject.ChildResults.ElementAt(1), folder.Children.ElementAt(1), "Danger", 1); }