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

add DisabledNoCoverage ( default true - no breaking change ) option #378

Merged
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
10 changes: 9 additions & 1 deletion FineCodeCoverageTests/AppOptionsProvider_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ public void Should_Default_Enabled_True()
DefaultTest(appOptions => appOptions.Enabled = true);
}

[Test]
public void Should_Default_DisabledNoCoverage_True()
{
DefaultTest(appOptions => appOptions.DisabledNoCoverage = true);
}

[Test]
public void Should_Default_True_ShowCoverageInOverviewMargin()
{
Expand Down Expand Up @@ -198,7 +204,8 @@ public void Should_Not_Default_Any_Other_AppOptions_Properties()
nameof(IAppOptions.ShowUncoveredInOverviewMargin),
nameof(IAppOptions.ShowPartiallyCoveredInOverviewMargin),
nameof(IAppOptions.ShowToolWindowToolbar),
nameof(IAppOptions.Hide0Coverable)
nameof(IAppOptions.Hide0Coverable),
nameof(IAppOptions.DisabledNoCoverage)
};
CollectionAssert.AreEquivalent(expectedSetters.Select(s => $"set_{s}"), invocationNames);
}
Expand Down Expand Up @@ -272,6 +279,7 @@ internal void Should_Use_Deseralized_String_From_Store_For_AppOption_Property(Fu
{ nameof(IAppOptions.CoverletConsoleGlobal), true},
{ nameof(IAppOptions.CoverletConsoleLocal), true},
{ nameof(IAppOptions.Enabled), true},
{ nameof(IAppOptions.DisabledNoCoverage), true},
{ nameof(IAppOptions.Exclude), new string[]{"exclude" } },
{ nameof(IAppOptions.ExcludeByAttribute), new string[]{ "ebyatt"} },
{ nameof(IAppOptions.ExcludeByFile), new string[]{ "ebyfile"} },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ internal class TestMsCodeCoverageOptions : IMsCodeCoverageOptions
public bool IncludeReferencedProjects { get; set; }
public string[] ExcludeAssemblies { get; set; }
public string[] IncludeAssemblies { get; set; }
public bool DisabledNoCoverage { get; set; }
}

internal static class ReplacementsAssertions
Expand Down Expand Up @@ -699,5 +700,6 @@ internal class TestCoverageProjectOptions : IAppOptions
public bool Hide0Coverage { get; set; }
public string[] ExcludeAssemblies { get; set; }
public string[] IncludeAssemblies { get; set; }
public bool DisabledNoCoverage { get; set; }
}
}
22 changes: 21 additions & 1 deletion FineCodeCoverageTests/TestContainerDiscovery_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ private void AssertShouldNotReloadCoverage()
mocker.Verify<IFCCEngine>(engine => engine.ReloadCoverage(It.IsAny<Func<Task<List<ICoverageProject>>>>()), Times.Never());
}

private void AssertReloadsCoverage()
{
mocker.Verify<IFCCEngine>(engine => engine.ReloadCoverage(It.IsAny<Func<Task<List<ICoverageProject>>>>()), Times.Once());
}

private void SetUpOptions(Action<Mock<IAppOptions>> setupAppOptions)
{
var mockAppOptions = new Mock<IAppOptions>();
Expand Down Expand Up @@ -252,18 +257,33 @@ public async Task Should_ReloadCoverage_When_TestExecutionStarting_And_Settings_
}

[Test]
public void Should_Not_ReloadCoverage_When_TestExecutionStarting_And_Settings_RunInParallel_Is_True_When_Enabled_is_False()
public void Should_Not_ReloadCoverage_When_TestExecutionStarting_And_Settings_RunInParallel_Is_True_When_Enabled_Is_False_And_DisabledNoCoverage_True()
{
SetUpOptions(mockAppOptions =>
{
mockAppOptions.Setup(o => o.Enabled).Returns(false);
mockAppOptions.Setup(o => o.RunInParallel).Returns(true);
mockAppOptions.Setup(o => o.DisabledNoCoverage).Returns(true);
});

RaiseTestExecutionStarting();
AssertShouldNotReloadCoverage();
}

[Test]
public void Should_ReloadCoverage_When_TestExecutionStarting_And_Settings_RunInParallel_Is_True_When_Enabled_Is_False_And_DisabledNoCoverage_False()
{
SetUpOptions(mockAppOptions =>
{
mockAppOptions.Setup(o => o.Enabled).Returns(false);
mockAppOptions.Setup(o => o.RunInParallel).Returns(true);
mockAppOptions.Setup(o => o.DisabledNoCoverage).Returns(false);
});

RaiseTestExecutionStarting();
AssertReloadsCoverage();
}

[TestCase(true, 10, 1, 0, true, Description = "Should run when tests fail if settings RunWhenTestsFail is true")]
[TestCase(false, 10, 1, 0, false, Description = "Should not run when tests fail if settings RunWhenTestsFail is false")]
[TestCase(false, 0, 1, 1, false, Description = "Should not run when total tests does not exceed the RunWhenTestsExceed setting")]
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ If you are using option 1) then project and global options will only be used whe
|Hide0Coverage|Set to true to hide classes, namespaces and assemblies that have 0% coverage.|
|Hide0Coverable|Set to false to show classes, namespaces and assemblies that are not coverable.|
|Enabled|Specifies whether or not coverage output is enabled|
|DisabledNoCoverage|Set to false for VS Option Enabled=false to not disable coverage|
|RunWhenTestsFail|By default coverage runs when tests fail. Set to false to prevent this. **Cannot be used in conjunction with RunInParallel**|
|RunWhenTestsExceed|Specify a value to only run coverage based upon the number of executing tests. **Cannot be used in conjunction with RunInParallel**|
|RunMsCodeCoverage|Change to IfInRunSettings to only collect with configured runsettings. Yes for runsettings generation.|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,19 @@ IMsCodeCoverageRunSettingsService msCodeCoverageRunSettingsService
ThreadHelper.JoinableTaskFactory.Run(taskProvider);
};

private bool CoverageDisabled(IAppOptions settings)
{
return !settings.Enabled && settings.DisabledNoCoverage;
}

private async Task TestExecutionStartingAsync(IOperation operation)
{
cancelling = false;
runningInParallel = false;
StopCoverage();

var settings = appOptionsProvider.Get();
if (!settings.Enabled)
if (CoverageDisabled(settings))
{
CombinedLog("Coverage not collected as FCC disabled.");
reportGeneratorUtil.EndOfCoverageRun();
Expand Down Expand Up @@ -155,7 +160,7 @@ private async Task TestExecutionFinishedAsync(IOperation operation)
private bool ShouldNotCollectWhenTestExecutionFinished()
{
settings = appOptionsProvider.Get();
return !settings.Enabled || runningInParallel || MsCodeCoverageErrored;
return CoverageDisabled(settings) || runningInParallel || MsCodeCoverageErrored;

}

Expand Down
4 changes: 4 additions & 0 deletions SharedProject/Options/AppOptionsPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ private static IAppOptionsStorageProvider GetAppOptionsStorageProvider()
[Description("Specifies whether or not coverage output is enabled")]
public bool Enabled { get; set; }

[Category(commonRunCategory)]
[Description("Set to false for VS Option Enabled=false to not disable coverage")]
public bool DisabledNoCoverage { get; set; }

[Category(commonRunCategory)]
[Description("Specifies whether or not the ms code coverage is used (BETA). No, IfInRunSettings, Yes")]
public RunMsCodeCoverage RunMsCodeCoverage { get; set; }
Expand Down
2 changes: 2 additions & 0 deletions SharedProject/Options/AppOptionsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ private void AddDefaults(IAppOptions appOptions)
appOptions.IncludeTestAssembly = true;
appOptions.ExcludeByFile = new[] { "**/Migrations/*" };
appOptions.Enabled = true;
appOptions.DisabledNoCoverage = true;
appOptions.ShowCoverageInOverviewMargin = true;
appOptions.ShowCoveredInOverviewMargin = true;
appOptions.ShowPartiallyCoveredInOverviewMargin = true;
Expand Down Expand Up @@ -200,6 +201,7 @@ internal class AppOptions : IAppOptions
public string[] FunctionsExclude { get; set; }

public bool Enabled { get; set; }
public bool DisabledNoCoverage { get; set; }

public bool IncludeTestAssembly { get; set; }

Expand Down
1 change: 1 addition & 0 deletions SharedProject/Options/IAppOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
internal interface IFCCCommonOptions
{
bool Enabled { get; set; }
bool DisabledNoCoverage { get; set; }
bool IncludeTestAssembly { get; set; }
bool IncludeReferencedProjects { get; set; }

Expand Down
Loading