From ecd7603f96ae7dcb1f2d49a0a68c03a99b78c4cd Mon Sep 17 00:00:00 2001 From: Liam Rougoor Date: Fri, 31 Jan 2025 14:03:20 +0100 Subject: [PATCH] add exclude-test-files-in-report option --- docs/configuration.md | 8 ++++++ .../Options/IStrykerOptions.cs | 1 + .../ConfigBuilderTests.cs | 1 + .../StrykerCLIInitCommandTests.cs | 5 +++- .../CommandLineConfigReader.cs | 1 + src/Stryker.CLI/Stryker.CLI/FileBasedInput.cs | 3 +++ .../Stryker.CLI/FileConfigReader.cs | 1 + .../Stryker.CLI/FileConfigWriter.cs | 3 ++- .../Inputs/ExcludeTestFilesInReportTests.cs | 27 +++++++++++++++++++ .../Stryker.Core/Reporters/Json/JsonReport.cs | 5 +++- .../Inputs/ExcludeTestFilesInReportInput.cs | 8 ++++++ src/Stryker.Options/Options/StrykerInputs.cs | 3 +++ src/Stryker.Options/Options/StrykerOptions.cs | 5 ++++ 13 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 src/Stryker.Core/Stryker.Core.UnitTest/Options/Inputs/ExcludeTestFilesInReportTests.cs create mode 100644 src/Stryker.Options/Options/Inputs/ExcludeTestFilesInReportInput.cs diff --git a/docs/configuration.md b/docs/configuration.md index e17625126f..c10e563b86 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -283,6 +283,14 @@ Config file: `report-file-name` If HTML and/or JSON reporting is being used you can use this option to change the report file name. +### `exclude-test-files-in-report` <`flag`> + +Default: `false` +Command line: `exclude-test-files-in-report` +Config file: `exclude-test-files-in-report` + +This flag excludes the test files from the json report. + ### `additional-timeout` <`number`> Default: `5000` diff --git a/src/Stryker.Abstractions/Options/IStrykerOptions.cs b/src/Stryker.Abstractions/Options/IStrykerOptions.cs index a7492e8e77..60fb074cfc 100644 --- a/src/Stryker.Abstractions/Options/IStrykerOptions.cs +++ b/src/Stryker.Abstractions/Options/IStrykerOptions.cs @@ -22,6 +22,7 @@ public interface IStrykerOptions IEnumerable DiffIgnoreChanges { get; init; } IEnumerable ExcludedLinqExpressions { get; init; } IEnumerable ExcludedMutations { get; init; } + bool ExcludeTestFilesInReport { get; init; } string FallbackVersion { get; init; } IEnumerable IgnoredMethods { get; init; } bool IsSolutionContext { get; } diff --git a/src/Stryker.CLI/Stryker.CLI.UnitTest/ConfigBuilderTests.cs b/src/Stryker.CLI/Stryker.CLI.UnitTest/ConfigBuilderTests.cs index 3495626175..05491ddbcf 100644 --- a/src/Stryker.CLI/Stryker.CLI.UnitTest/ConfigBuilderTests.cs +++ b/src/Stryker.CLI/Stryker.CLI.UnitTest/ConfigBuilderTests.cs @@ -224,6 +224,7 @@ private static Mock GetMockInputs() inputs.Setup(x => x.ReportFileNameInput).Returns(new ReportFileNameInput()); inputs.Setup(x => x.BreakOnInitialTestFailureInput).Returns(new BreakOnInitialTestFailureInput()); inputs.Setup(x => x.OutputPathInput).Returns(new OutputPathInput()); + inputs.Setup(x => x.ExcludeTestFilesInReportInput).Returns(new ExcludeTestFilesInReportInput()); return inputs; } diff --git a/src/Stryker.CLI/Stryker.CLI.UnitTest/StrykerCLIInitCommandTests.cs b/src/Stryker.CLI/Stryker.CLI.UnitTest/StrykerCLIInitCommandTests.cs index 7b6416200c..983a680a64 100644 --- a/src/Stryker.CLI/Stryker.CLI.UnitTest/StrykerCLIInitCommandTests.cs +++ b/src/Stryker.CLI/Stryker.CLI.UnitTest/StrykerCLIInitCommandTests.cs @@ -58,6 +58,7 @@ public void Init() config.TestProjects.ShouldBe(new TestProjectsInput().Default); config.DashboardUrl.ShouldBe(new DashboardUrlInput().Default); config.BreakOnInitialTestFailure.ShouldBe(new BreakOnInitialTestFailureInput().Default); + config.ExcludeTestFilesInReport.ShouldBe(new ExcludeTestFilesInReportInput().Default); } [TestMethod] @@ -123,7 +124,8 @@ public void InitOverride() "--mutation-level", "advanced", "--disable-bail", "--test-project", "testProject", - "--break-on-initial-test-failure" + "--break-on-initial-test-failure", + "--exclude-test-files-in-report" }); _strykerRunnerMock.VerifyAll(); @@ -144,5 +146,6 @@ public void InitOverride() config.DisableBail.ShouldBe(true); config.TestProjects.ShouldHaveSingleItem().ShouldBe("testProject"); config.BreakOnInitialTestFailure.ShouldBe(true); + config.ExcludeTestFilesInReport.ShouldBe(true); } } diff --git a/src/Stryker.CLI/Stryker.CLI/CommandLineConfig/CommandLineConfigReader.cs b/src/Stryker.CLI/Stryker.CLI/CommandLineConfig/CommandLineConfigReader.cs index 04f0973d7e..944e48ffd5 100644 --- a/src/Stryker.CLI/Stryker.CLI/CommandLineConfig/CommandLineConfigReader.cs +++ b/src/Stryker.CLI/Stryker.CLI/CommandLineConfig/CommandLineConfigReader.cs @@ -204,6 +204,7 @@ private void PrepareCliOptions(IStrykerInputs inputs) AddCliInput(inputs.DashboardApiKeyInput, "dashboard-api-key", null, category: InputCategory.Reporting); AddCliInput(inputs.AzureFileStorageSasInput, "azure-fileshare-sas", null, category: InputCategory.Reporting); AddCliInput(inputs.OutputPathInput, "output", "O", optionType: CommandOptionType.SingleValue, category: InputCategory.Reporting); + AddCliInput(inputs.ExcludeTestFilesInReportInput, "exclude-test-files-in-report", null, optionType: CommandOptionType.NoValue, category: InputCategory.Reporting); // Category: Misc AddCliInput(inputs.BreakOnInitialTestFailureInput, "break-on-initial-test-failure", null, optionType: CommandOptionType.NoValue, category: InputCategory.Misc); AddCliInput(inputs.DevModeInput, "dev-mode", null, optionType: CommandOptionType.NoValue, category: InputCategory.Misc); diff --git a/src/Stryker.CLI/Stryker.CLI/FileBasedInput.cs b/src/Stryker.CLI/Stryker.CLI/FileBasedInput.cs index 4677f157b5..0d3e00aed4 100644 --- a/src/Stryker.CLI/Stryker.CLI/FileBasedInput.cs +++ b/src/Stryker.CLI/Stryker.CLI/FileBasedInput.cs @@ -94,6 +94,9 @@ public class FileBasedInput : IExtraData [JsonPropertyName("break-on-initial-test-failure")] public bool? BreakOnInitialTestFailure { get; init; } + [JsonPropertyName("exclude-test-files-in-report")] + public bool? ExcludeTestFilesInReport { get; init; } + [JsonExtensionData] public Dictionary ExtraData { get; init; } } diff --git a/src/Stryker.CLI/Stryker.CLI/FileConfigReader.cs b/src/Stryker.CLI/Stryker.CLI/FileConfigReader.cs index 0378d57c5a..02bcdceb25 100644 --- a/src/Stryker.CLI/Stryker.CLI/FileConfigReader.cs +++ b/src/Stryker.CLI/Stryker.CLI/FileConfigReader.cs @@ -71,6 +71,7 @@ public static void DeserializeConfig(string configFilePath, IStrykerInputs input inputs.ReportFileNameInput.SuppliedInput = config.ReportFileName; inputs.BreakOnInitialTestFailureInput.SuppliedInput = config.BreakOnInitialTestFailure; + inputs.ExcludeTestFilesInReportInput.SuppliedInput = config.ExcludeTestFilesInReport; } private static FileBasedInput LoadConfig(string configFilePath) diff --git a/src/Stryker.CLI/Stryker.CLI/FileConfigWriter.cs b/src/Stryker.CLI/Stryker.CLI/FileConfigWriter.cs index 3dc31f7bdb..5bbfc13705 100644 --- a/src/Stryker.CLI/Stryker.CLI/FileConfigWriter.cs +++ b/src/Stryker.CLI/Stryker.CLI/FileConfigWriter.cs @@ -63,7 +63,8 @@ private static FileBasedInputOuter CreateConfig(IStrykerInputs inputs) IgnoreMethods = inputs.IgnoredMethodsInput.SuppliedInput?.ToArray() ?? inputs.IgnoredMethodsInput.Default.ToArray(), ReportFileName = inputs.ReportFileNameInput.SuppliedInput ?? inputs.ReportFileNameInput.Default, BreakOnInitialTestFailure = inputs.BreakOnInitialTestFailureInput.SuppliedInput ?? inputs.BreakOnInitialTestFailureInput.Default, - Concurrency = inputs.ConcurrencyInput.SuppliedInput ?? inputs.ConcurrencyInput.Default + Concurrency = inputs.ConcurrencyInput.SuppliedInput ?? inputs.ConcurrencyInput.Default, + ExcludeTestFilesInReport = inputs.ExcludeTestFilesInReportInput.SuppliedInput ?? inputs.ExcludeTestFilesInReportInput.Default } }; } diff --git a/src/Stryker.Core/Stryker.Core.UnitTest/Options/Inputs/ExcludeTestFilesInReportTests.cs b/src/Stryker.Core/Stryker.Core.UnitTest/Options/Inputs/ExcludeTestFilesInReportTests.cs new file mode 100644 index 0000000000..a190276004 --- /dev/null +++ b/src/Stryker.Core/Stryker.Core.UnitTest/Options/Inputs/ExcludeTestFilesInReportTests.cs @@ -0,0 +1,27 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Shouldly; +using Stryker.Abstractions.Options.Inputs; + +namespace Stryker.Core.UnitTest.Options.Inputs; + +[TestClass] +public class ExcludeTestFilesInReportTests : TestBase +{ + [TestMethod] + public void ShouldHaveHelpText() + { + var target = new ExcludeTestFilesInReportInput(); + target.HelpText.ShouldBe("Exclude test files in the report. This may reduce the size of the report significantly. | default: 'False'"); + } + + [TestMethod] + [DataRow(null, false)] + [DataRow(false, false)] + [DataRow(true, true)] + public void ShouldTranslateInputToExpectedResult(bool? argValue, bool expected) + { + var validatedInput = new ExcludeTestFilesInReportInput { SuppliedInput = argValue }.Validate(); + + validatedInput.ShouldBe(expected); + } +} diff --git a/src/Stryker.Core/Stryker.Core/Reporters/Json/JsonReport.cs b/src/Stryker.Core/Stryker.Core/Reporters/Json/JsonReport.cs index 86162cd459..4b113d7e1d 100644 --- a/src/Stryker.Core/Stryker.Core/Reporters/Json/JsonReport.cs +++ b/src/Stryker.Core/Stryker.Core/Reporters/Json/JsonReport.cs @@ -26,7 +26,10 @@ private JsonReport(IStrykerOptions options, IReadOnlyProjectComponent mutationRe ProjectRoot = mutationReport.FullPath; Merge(Files, GenerateReportComponents(mutationReport)); - AddTestFiles(testProjectsInfo); + if (!options.ExcludeTestFilesInReport) + { + AddTestFiles(testProjectsInfo); + } } public static IJsonReport Build(IStrykerOptions options, IReadOnlyProjectComponent mutationReport, ITestProjectsInfo testProjectsInfo) => new JsonReport(options, mutationReport, testProjectsInfo); diff --git a/src/Stryker.Options/Options/Inputs/ExcludeTestFilesInReportInput.cs b/src/Stryker.Options/Options/Inputs/ExcludeTestFilesInReportInput.cs new file mode 100644 index 0000000000..99183ec8ca --- /dev/null +++ b/src/Stryker.Options/Options/Inputs/ExcludeTestFilesInReportInput.cs @@ -0,0 +1,8 @@ +namespace Stryker.Abstractions.Options.Inputs; + +public class ExcludeTestFilesInReportInput : Input +{ + public override bool? Default => false; + protected override string Description => "Exclude test files in the report. This may reduce the size of the report significantly."; + public bool Validate() => SuppliedInput ?? false; +} diff --git a/src/Stryker.Options/Options/StrykerInputs.cs b/src/Stryker.Options/Options/StrykerInputs.cs index ae0679c478..88ac26d48d 100644 --- a/src/Stryker.Options/Options/StrykerInputs.cs +++ b/src/Stryker.Options/Options/StrykerInputs.cs @@ -21,6 +21,7 @@ public interface IStrykerInputs DiffIgnoreChangesInput DiffIgnoreChangesInput { get; init; } DisableBailInput DisableBailInput { get; set; } DisableMixMutantsInput DisableMixMutantsInput { get; set; } + ExcludeTestFilesInReportInput ExcludeTestFilesInReportInput { get; init; } IgnoreMutationsInput IgnoreMutationsInput { get; init; } FallbackVersionInput FallbackVersionInput { get; init; } IgnoreMethodsInput IgnoredMethodsInput { get; init; } @@ -107,6 +108,7 @@ public StrykerInputs(IFileSystem fileSystem = null) public OpenReportInput OpenReportInput { get; init; } = new(); public OpenReportEnabledInput OpenReportEnabledInput { get; init; } = new(); public BreakOnInitialTestFailureInput BreakOnInitialTestFailureInput { get; init; } = new(); + public ExcludeTestFilesInReportInput ExcludeTestFilesInReportInput { get; init; } = new(); public IStrykerOptions ValidateAll() { @@ -148,6 +150,7 @@ public IStrykerOptions ValidateAll() AdditionalTimeout = AdditionalTimeoutInput.Validate(), ExcludedMutations = IgnoreMutationsInput.Validate(), ExcludedLinqExpressions = IgnoreMutationsInput.ValidateLinqExpressions(), + ExcludeTestFilesInReport = ExcludeTestFilesInReportInput.Validate(), IgnoredMethods = IgnoredMethodsInput.Validate(), Mutate = MutateInput.Validate(), LanguageVersion = LanguageVersionInput.Validate(), diff --git a/src/Stryker.Options/Options/StrykerOptions.cs b/src/Stryker.Options/Options/StrykerOptions.cs index b5948009d7..774a84f3f9 100644 --- a/src/Stryker.Options/Options/StrykerOptions.cs +++ b/src/Stryker.Options/Options/StrykerOptions.cs @@ -232,6 +232,11 @@ public class StrykerOptions : IStrykerOptions /// public IProvideId MutantIdProvider {get; set;} + /// + /// When true, excludes the test files in the report. + /// + public bool ExcludeTestFilesInReport { get; init; } + private readonly string _workingDirectoryField;