Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(config): add exclude-test-files-in-report option #3179

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of a separate option, perhaps we could split the reporters into source and test reporters?


Default: `false`
Command line: `exclude-test-files-in-report`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is needed as a command line option. Either your project is too large to be able to include unit test results, or it's not. That sounds like static config to me.

Config file: `exclude-test-files-in-report`

This flag excludes the test files from the json report.

### `additional-timeout` <`number`>

Default: `5000`
Expand Down
1 change: 1 addition & 0 deletions src/Stryker.Abstractions/Options/IStrykerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public interface IStrykerOptions
IEnumerable<IExclusionPattern> DiffIgnoreChanges { get; init; }
IEnumerable<LinqExpression> ExcludedLinqExpressions { get; init; }
IEnumerable<Mutator> ExcludedMutations { get; init; }
bool ExcludeTestFilesInReport { get; init; }
string FallbackVersion { get; init; }
IEnumerable<Regex> IgnoredMethods { get; init; }
bool IsSolutionContext { get; }
Expand Down
1 change: 1 addition & 0 deletions src/Stryker.CLI/Stryker.CLI.UnitTest/ConfigBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ private static Mock<IStrykerInputs> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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();
Expand All @@ -144,5 +146,6 @@ public void InitOverride()
config.DisableBail.ShouldBe(true);
config.TestProjects.ShouldHaveSingleItem().ShouldBe("testProject");
config.BreakOnInitialTestFailure.ShouldBe(true);
config.ExcludeTestFilesInReport.ShouldBe(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/Stryker.CLI/Stryker.CLI/FileBasedInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, JsonElement> ExtraData { get; init; }
}
Expand Down
1 change: 1 addition & 0 deletions src/Stryker.CLI/Stryker.CLI/FileConfigReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/Stryker.CLI/Stryker.CLI/FileConfigWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
5 changes: 4 additions & 1 deletion src/Stryker.Core/Stryker.Core/Reporters/Json/JsonReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Stryker.Abstractions.Options.Inputs;

public class ExcludeTestFilesInReportInput : Input<bool?>
{
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;
}
3 changes: 3 additions & 0 deletions src/Stryker.Options/Options/StrykerInputs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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()
{
Expand Down Expand Up @@ -148,6 +150,7 @@ public IStrykerOptions ValidateAll()
AdditionalTimeout = AdditionalTimeoutInput.Validate(),
ExcludedMutations = IgnoreMutationsInput.Validate<Mutator>(),
ExcludedLinqExpressions = IgnoreMutationsInput.ValidateLinqExpressions(),
ExcludeTestFilesInReport = ExcludeTestFilesInReportInput.Validate(),
IgnoredMethods = IgnoredMethodsInput.Validate(),
Mutate = MutateInput.Validate(),
LanguageVersion = LanguageVersionInput.Validate(),
Expand Down
5 changes: 5 additions & 0 deletions src/Stryker.Options/Options/StrykerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,11 @@ public class StrykerOptions : IStrykerOptions
/// </summary>
public IProvideId MutantIdProvider {get; set;}

/// <summary>
/// When true, excludes the test files in the report.
/// </summary>
public bool ExcludeTestFilesInReport { get; init; }


private readonly string _workingDirectoryField;

Expand Down
Loading