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 MaxAttempts trait to retry-able tests #85

Merged
merged 3 commits into from
Jun 6, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected override IXunitTestCase CreateTestCase(ITestFrameworkDiscoveryOptions

UISettingsAttribute settings = UIFactDiscoverer.GetSettings(testMethod);
return RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
? (IXunitTestCase)new UITestCase(UITestCase.SyncContextType.WinForms, this.diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), testMethod, testMethodArguments: null, settings)
? new UITestCase(UITestCase.SyncContextType.WinForms, this.diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), testMethod, testMethodArguments: null, settings)
: new XunitSkippedDataRowTestCase(this.diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), discoveryOptions.MethodDisplayOptionsOrDefault(), testMethod, "WinForms only exists on Windows.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ protected override IEnumerable<IXunitTestCase> CreateTestCasesForDataRow(ITestFr
{
UISettingsAttribute settings = UIFactDiscoverer.GetSettings(testMethod);
yield return RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
? (IXunitTestCase)new UITestCase(UITestCase.SyncContextType.WinForms, this.DiagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), testMethod, dataRow, settings)
? new UITestCase(UITestCase.SyncContextType.WinForms, this.DiagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), testMethod, dataRow, settings)
: new XunitSkippedDataRowTestCase(this.DiagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), discoveryOptions.MethodDisplayOptionsOrDefault(), testMethod, "WinForms only exists on Windows.");
}

protected override IEnumerable<IXunitTestCase> CreateTestCasesForTheory(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo theoryAttribute)
{
UISettingsAttribute settings = UIFactDiscoverer.GetSettings(testMethod);
yield return RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
? (IXunitTestCase)new UITheoryTestCase(UITestCase.SyncContextType.WinForms, this.DiagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), TestMethodDisplayOptions.None, testMethod, settings)
? new UITheoryTestCase(UITestCase.SyncContextType.WinForms, this.DiagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), TestMethodDisplayOptions.None, testMethod, settings)
: new XunitSkippedDataRowTestCase(this.DiagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), discoveryOptions.MethodDisplayOptionsOrDefault(), testMethod, "WinForms only exists on Windows.");
}
}
2 changes: 1 addition & 1 deletion src/Xunit.StaFact/Sdk.WindowsDesktop/WpfFactDiscoverer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected override IXunitTestCase CreateTestCase(ITestFrameworkDiscoveryOptions

UISettingsAttribute settings = UIFactDiscoverer.GetSettings(testMethod);
return RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
? (IXunitTestCase)new UITestCase(UITestCase.SyncContextType.WPF, this.diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), testMethod, testMethodArguments: null, settings)
? new UITestCase(UITestCase.SyncContextType.WPF, this.diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), testMethod, testMethodArguments: null, settings)
: new XunitSkippedDataRowTestCase(this.diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), discoveryOptions.MethodDisplayOptionsOrDefault(), testMethod, "WPF only exists on Windows.");
}
}
4 changes: 2 additions & 2 deletions src/Xunit.StaFact/Sdk.WindowsDesktop/WpfTheoryDiscoverer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ protected override IEnumerable<IXunitTestCase> CreateTestCasesForDataRow(ITestFr
{
UISettingsAttribute settings = UIFactDiscoverer.GetSettings(testMethod);
yield return RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
? (IXunitTestCase)new UITestCase(UITestCase.SyncContextType.WPF, this.DiagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), testMethod, dataRow, settings)
? new UITestCase(UITestCase.SyncContextType.WPF, this.DiagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), testMethod, dataRow, settings)
: new XunitSkippedDataRowTestCase(this.DiagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), discoveryOptions.MethodDisplayOptionsOrDefault(), testMethod, "WPF only exists on Windows.");
}

protected override IEnumerable<IXunitTestCase> CreateTestCasesForTheory(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo theoryAttribute)
{
UISettingsAttribute settings = UIFactDiscoverer.GetSettings(testMethod);
yield return RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
? (IXunitTestCase)new UITheoryTestCase(UITestCase.SyncContextType.WPF, this.DiagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), TestMethodDisplayOptions.None, testMethod, settings)
? new UITheoryTestCase(UITestCase.SyncContextType.WPF, this.DiagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), TestMethodDisplayOptions.None, testMethod, settings)
: new XunitSkippedDataRowTestCase(this.DiagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), discoveryOptions.MethodDisplayOptionsOrDefault(), testMethod, "WPF only exists on Windows.");
}
}
2 changes: 1 addition & 1 deletion src/Xunit.StaFact/Sdk/StaFactDiscoverer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected override IXunitTestCase CreateTestCase(ITestFrameworkDiscoveryOptions

UISettingsAttribute settings = UIFactDiscoverer.GetSettings(testMethod);
return RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
? (IXunitTestCase)new UITestCase(UITestCase.SyncContextType.None, this.diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), testMethod, testMethodArguments: null, settings)
? new UITestCase(UITestCase.SyncContextType.None, this.diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), testMethod, testMethodArguments: null, settings)
: new XunitSkippedDataRowTestCase(this.diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), discoveryOptions.MethodDisplayOptionsOrDefault(), testMethod, "STA threads only exist on Windows.");
}
}
4 changes: 2 additions & 2 deletions src/Xunit.StaFact/Sdk/StaTheoryDiscoverer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected override IEnumerable<IXunitTestCase> CreateTestCasesForDataRow(ITestFr

UISettingsAttribute settings = UIFactDiscoverer.GetSettings(testMethod);
yield return RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
? (IXunitTestCase)new UITestCase(UITestCase.SyncContextType.None, this.DiagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), testMethod, dataRow, settings)
? new UITestCase(UITestCase.SyncContextType.None, this.DiagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), testMethod, dataRow, settings)
: new XunitSkippedDataRowTestCase(this.DiagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), discoveryOptions.MethodDisplayOptionsOrDefault(), testMethod, "STA threads only exist on Windows.");
}

Expand All @@ -53,7 +53,7 @@ protected override IEnumerable<IXunitTestCase> CreateTestCasesForTheory(ITestFra

UISettingsAttribute settings = UIFactDiscoverer.GetSettings(testMethod);
yield return RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
? (IXunitTestCase)new UITheoryTestCase(UITestCase.SyncContextType.None, this.DiagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), TestMethodDisplayOptions.None, testMethod, settings)
? new UITheoryTestCase(UITestCase.SyncContextType.None, this.DiagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), TestMethodDisplayOptions.None, testMethod, settings)
: new XunitSkippedDataRowTestCase(this.DiagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), discoveryOptions.MethodDisplayOptionsOrDefault(), testMethod, "STA threads only exist on Windows.");
}
}
1 change: 1 addition & 0 deletions src/Xunit.StaFact/Sdk/UITestCase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ internal UITestCase(
: base(diagnosticMessageSink, defaultMethodDisplay, TestMethodDisplayOptions.None, testMethod, testMethodArguments)
{
this.settings = settings;
settings.ApplyTraits(this);
this.synchronizationContextType = synchronizationContextType;
}

Expand Down
1 change: 1 addition & 0 deletions src/Xunit.StaFact/Sdk/UITheoryTestCase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ internal UITheoryTestCase(UITestCase.SyncContextType synchronizationContextType,
: base(diagnosticMessageSink, defaultMethodDisplay, defaultMethodDisplayOptions, testMethod)
{
this.Settings = settings;
settings.ApplyTraits(this);
this.SynchronizationContextType = synchronizationContextType;
}

Expand Down
17 changes: 17 additions & 0 deletions src/Xunit.StaFact/UISettingsAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Andrew Arnott. All rights reserved.
// Licensed under the Ms-PL license. See LICENSE file in the project root for full license information.

using Xunit.Sdk;

namespace Xunit;

[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
Expand All @@ -19,4 +21,19 @@ public sealed class UISettingsAttribute : Attribute
public int MaxAttempts { get; set; }

internal static UISettingsAttribute Default => new() { MaxAttempts = 1 };

/// <summary>
/// Applies traits to a test case based on the settings in this attribute.
/// </summary>
/// <param name="testCase">The test case to add traits to.</param>
internal void ApplyTraits(XunitTestCase testCase)
{
if (this.MaxAttempts > 1)
{
if (!testCase.Traits.ContainsKey("MaxAttempts"))
{
testCase.Traits.Add("MaxAttempts", new() { this.MaxAttempts.ToString() });
}
}
}
}
23 changes: 20 additions & 3 deletions test/Xunit.StaFact.Tests/MaxAttemptsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the Ms-PL license. See LICENSE file in the project root for full license information.

using System.Runtime.CompilerServices;
using Xunit.Sdk;

internal static class MaxAttemptsHelper
{
Expand All @@ -12,8 +13,8 @@ internal static class MaxAttemptsHelper
/// </summary>
/// <param name="testClass">The class defining the test.</param>
/// <param name="testMethod">The unique name of the test method within <paramref name="testClass"/>.</param>
/// <returns>The 0-based attempt number (the value before it was incremented).</returns>
public static int GetAndIncrementAttemptNumber(Type testClass, string testMethod)
/// <returns>The current (1-based) attempt number.</returns>
internal static int GetAndIncrementAttemptNumber(Type testClass, string testMethod)
{
StrongBox<int>? attemptNumber;
lock (AttemptNumber)
Expand All @@ -25,6 +26,22 @@ public static int GetAndIncrementAttemptNumber(Type testClass, string testMethod
}
}

return Interlocked.Increment(ref attemptNumber.Value) - 1;
return Interlocked.Increment(ref attemptNumber.Value);
}

/// <summary>
/// Throws an exception to fail a test if the current attempt number is not the one designated as the passing one.
/// </summary>
/// <param name="testClass">The test class type. Used for counting attempts.</param>
/// <param name="testMethod">The name of the test method, including any theory arguments. Used for counting attempts.</param>
/// <param name="passingAttemptNumber">The attempt number which should pass.</param>
/// <exception cref="FailException">Thrown when the <paramref name="passingAttemptNumber"/> does not match the current attempt number.</exception>
internal static void ThrowUnlessAttemptNumber(Type testClass, string testMethod, int passingAttemptNumber)
{
int attemptNumber = GetAndIncrementAttemptNumber(testClass, testMethod);
if (attemptNumber != passingAttemptNumber)
{
Assert.Fail($"This test fails on attempt {attemptNumber} (but is expected to pass on attempt {passingAttemptNumber}).");
}
}
}
16 changes: 2 additions & 14 deletions test/Xunit.StaFact.Tests/StaFactTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,11 @@ public async void AsyncVoid_IsNotSupported()

[DesktopFact]
[UISettings(MaxAttempts = 2)]
public void AutomaticRetryNeeded()
{
if (MaxAttemptsHelper.GetAndIncrementAttemptNumber(this.GetType(), MethodBase.GetCurrentMethod()!.Name) != 1)
{
Assert.Fail("The first attempt false, but a second attempt will pass.");
}
}
public void AutomaticRetryNeeded() => MaxAttemptsHelper.ThrowUnlessAttemptNumber(this.GetType(), MethodBase.GetCurrentMethod()!.Name, 2);

[DesktopFact]
[UISettings(MaxAttempts = 2)]
public void AutomaticRetryNotNeeded()
{
if (MaxAttemptsHelper.GetAndIncrementAttemptNumber(this.GetType(), MethodBase.GetCurrentMethod()!.Name) != 0)
{
Assert.Fail("This test should not have run a second time because the first run was successful.");
}
}
public void AutomaticRetryNotNeeded() => MaxAttemptsHelper.ThrowUnlessAttemptNumber(this.GetType(), MethodBase.GetCurrentMethod()!.Name, 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

💭 With CallerFilePath and CallerLineNumber, you could probably get this down to:

MaxAttemptsHelper.ThrowUnlessAttemptNumber(1)

Copy link
Owner Author

Choose a reason for hiding this comment

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

Not for theories. But I agree we could remove the test class argument. File path would work until we have derived test classes that inherit tests. But this repo doesn't and isn't likely to have those.
I think I'll leave it as-is though for now.


[DesktopFact, Trait("TestCategory", "FailureExpected")]
[UISettings(MaxAttempts = 2)]
Expand Down
16 changes: 2 additions & 14 deletions test/Xunit.StaFact.Tests/StaTheoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,25 +77,13 @@ public void ThreadAffinitizedDataObject(NonSerializableObject o)
[InlineData(0)]
[InlineData(1)]
[UISettings(MaxAttempts = 2)]
public void AutomaticRetryNeeded(int arg)
{
if (MaxAttemptsHelper.GetAndIncrementAttemptNumber(this.GetType(), $"{MethodBase.GetCurrentMethod()!.Name}_{arg}") != 1)
{
Assert.Fail("The first attempt false, but a second attempt will pass.");
}
}
public void AutomaticRetryNeeded(int arg) => MaxAttemptsHelper.ThrowUnlessAttemptNumber(this.GetType(), $"{MethodBase.GetCurrentMethod()!.Name}_{arg}", 2);

[DesktopTheory]
[InlineData(0)]
[InlineData(1)]
[UISettings(MaxAttempts = 2)]
public void AutomaticRetryNotNeeded(int arg)
{
if (MaxAttemptsHelper.GetAndIncrementAttemptNumber(this.GetType(), $"{MethodBase.GetCurrentMethod()!.Name}_{arg}") != 0)
{
Assert.Fail("This test should not have run a second time because the first run was successful.");
}
}
public void AutomaticRetryNotNeeded(int arg) => MaxAttemptsHelper.ThrowUnlessAttemptNumber(this.GetType(), $"{MethodBase.GetCurrentMethod()!.Name}_{arg}", 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

📝 The inclusion of arg here makes it more difficult to simplify

Copy link
Owner Author

Choose a reason for hiding this comment

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

I don't see a way to avoid it. You added it originally. 😉


[DesktopTheory, Trait("TestCategory", "FailureExpected")]
[InlineData(0)]
Expand Down
32 changes: 4 additions & 28 deletions test/Xunit.StaFact.Tests/UIFactTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,23 +147,11 @@ await Task.Run(delegate

[DesktopFact]
[UISettings(MaxAttempts = 2)]
public void AutomaticRetryNeeded()
{
if (MaxAttemptsHelper.GetAndIncrementAttemptNumber(this.GetType(), MethodBase.GetCurrentMethod()!.Name) != 1)
{
Assert.Fail("The first attempt false, but a second attempt will pass.");
}
}
public void AutomaticRetryNeeded() => MaxAttemptsHelper.ThrowUnlessAttemptNumber(this.GetType(), MethodBase.GetCurrentMethod()!.Name, 2);

[DesktopFact]
[UISettings(MaxAttempts = 2)]
public void AutomaticRetryNotNeeded()
{
if (MaxAttemptsHelper.GetAndIncrementAttemptNumber(this.GetType(), MethodBase.GetCurrentMethod()!.Name) != 0)
{
Assert.Fail("This test should not have run a second time because the first run was successful.");
}
}
public void AutomaticRetryNotNeeded() => MaxAttemptsHelper.ThrowUnlessAttemptNumber(this.GetType(), MethodBase.GetCurrentMethod()!.Name, 1);

[DesktopFact, Trait("TestCategory", "FailureExpected")]
[UISettings(MaxAttempts = 2)]
Expand All @@ -176,13 +164,7 @@ public void FailsAllRetries()
public class ClassWithDefaultRetryPolicy
{
[DesktopFact]
public void AutomaticRetryNeeded()
{
if (MaxAttemptsHelper.GetAndIncrementAttemptNumber(this.GetType(), MethodBase.GetCurrentMethod()!.Name) != 1)
{
Assert.Fail("The first attempt false, but a second attempt will pass.");
}
}
public void AutomaticRetryNeeded() => MaxAttemptsHelper.ThrowUnlessAttemptNumber(this.GetType(), MethodBase.GetCurrentMethod()!.Name, 2);

[DesktopFact, Trait("TestCategory", "FailureExpected")]
public void FailsAllRetries()
Expand All @@ -192,12 +174,6 @@ public void FailsAllRetries()

[DesktopFact]
[UISettings(MaxAttempts = 3)]
public void SucceedOn3rdAttempt()
{
if (MaxAttemptsHelper.GetAndIncrementAttemptNumber(this.GetType(), MethodBase.GetCurrentMethod()!.Name) != 2)
{
Assert.Fail("This attempt should fail except for the 3rd attempt.");
}
}
public void SucceedOn3rdAttempt() => MaxAttemptsHelper.ThrowUnlessAttemptNumber(this.GetType(), MethodBase.GetCurrentMethod()!.Name, 3);
}
}
16 changes: 2 additions & 14 deletions test/Xunit.StaFact.Tests/UITheoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,25 +151,13 @@ public void ThreadAffinitizedDataObject(NonSerializableObject o)
[InlineData(0)]
[InlineData(1)]
[UISettings(MaxAttempts = 2)]
public void AutomaticRetryNeeded(int arg)
{
if (MaxAttemptsHelper.GetAndIncrementAttemptNumber(this.GetType(), $"{MethodBase.GetCurrentMethod()!.Name}_{arg}") != 1)
{
Assert.Fail("The first attempt false, but a second attempt will pass.");
}
}
public void AutomaticRetryNeeded(int arg) => MaxAttemptsHelper.ThrowUnlessAttemptNumber(this.GetType(), $"{MethodBase.GetCurrentMethod()!.Name}_{arg}", 2);

[DesktopTheory]
[InlineData(0)]
[InlineData(1)]
[UISettings(MaxAttempts = 2)]
public void AutomaticRetryNotNeeded(int arg)
{
if (MaxAttemptsHelper.GetAndIncrementAttemptNumber(this.GetType(), $"{MethodBase.GetCurrentMethod()!.Name}_{arg}") != 0)
{
Assert.Fail("This test should not have run a second time because the first run was successful.");
}
}
public void AutomaticRetryNotNeeded(int arg) => MaxAttemptsHelper.ThrowUnlessAttemptNumber(this.GetType(), $"{MethodBase.GetCurrentMethod()!.Name}_{arg}", 1);

[DesktopTheory, Trait("TestCategory", "FailureExpected")]
[InlineData(0)]
Expand Down
16 changes: 2 additions & 14 deletions test/Xunit.StaFact.Tests/WindowsDesktop/WinFormsFactTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,11 @@ public async Task OperationCanceledException_Thrown()

[DesktopFact]
[UISettings(MaxAttempts = 2)]
public void AutomaticRetryNeeded()
{
if (MaxAttemptsHelper.GetAndIncrementAttemptNumber(this.GetType(), MethodBase.GetCurrentMethod()!.Name) != 1)
{
Assert.Fail("The first attempt false, but a second attempt will pass.");
}
}
public void AutomaticRetryNeeded() => MaxAttemptsHelper.ThrowUnlessAttemptNumber(this.GetType(), MethodBase.GetCurrentMethod()!.Name, 2);

[DesktopFact]
[UISettings(MaxAttempts = 2)]
public void AutomaticRetryNotNeeded()
{
if (MaxAttemptsHelper.GetAndIncrementAttemptNumber(this.GetType(), MethodBase.GetCurrentMethod()!.Name) != 0)
{
Assert.Fail("This test should not have run a second time because the first run was successful.");
}
}
public void AutomaticRetryNotNeeded() => MaxAttemptsHelper.ThrowUnlessAttemptNumber(this.GetType(), MethodBase.GetCurrentMethod()!.Name, 1);

[DesktopFact, Trait("TestCategory", "FailureExpected")]
[UISettings(MaxAttempts = 2)]
Expand Down
16 changes: 2 additions & 14 deletions test/Xunit.StaFact.Tests/WindowsDesktop/WinFormsTheoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,13 @@ public void ThreadAffinitizedDataObject(NonSerializableObject o)
[InlineData(0)]
[InlineData(1)]
[UISettings(MaxAttempts = 2)]
public void AutomaticRetryNeeded(int arg)
{
if (MaxAttemptsHelper.GetAndIncrementAttemptNumber(this.GetType(), $"{MethodBase.GetCurrentMethod()!.Name}_{arg}") != 1)
{
Assert.Fail("The first attempt false, but a second attempt will pass.");
}
}
public void AutomaticRetryNeeded(int arg) => MaxAttemptsHelper.ThrowUnlessAttemptNumber(this.GetType(), $"{MethodBase.GetCurrentMethod()!.Name}_{arg}", 2);

[DesktopTheory]
[InlineData(0)]
[InlineData(1)]
[UISettings(MaxAttempts = 2)]
public void AutomaticRetryNotNeeded(int arg)
{
if (MaxAttemptsHelper.GetAndIncrementAttemptNumber(this.GetType(), $"{MethodBase.GetCurrentMethod()!.Name}_{arg}") != 0)
{
Assert.Fail("This test should not have run a second time because the first run was successful.");
}
}
public void AutomaticRetryNotNeeded(int arg) => MaxAttemptsHelper.ThrowUnlessAttemptNumber(this.GetType(), $"{MethodBase.GetCurrentMethod()!.Name}_{arg}", 1);

[DesktopTheory, Trait("TestCategory", "FailureExpected")]
[InlineData(0)]
Expand Down
Loading