You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// Overrides the test result with a passed state and custom reason.
52
-
/// Useful for marking tests as passed under special conditions.
51
+
/// Overrides the test result with a specific state and custom reason.
53
52
/// </summary>
53
+
/// <param name="state">The desired test state (Passed, Failed, Skipped, Timeout, or Cancelled)</param>
54
54
/// <param name="reason">The reason for overriding the result (cannot be empty)</param>
55
-
/// <exception cref="ArgumentException">Thrown when reason is emptyor whitespace</exception>
55
+
/// <exception cref="ArgumentException">Thrown when reason is empty, whitespace, or state is invalid (NotStarted, WaitingForDependencies, Queued, Running)</exception>
56
56
/// <exception cref="InvalidOperationException">Thrown when result has already been overridden</exception>
57
57
/// <remarks>
58
58
/// This method can only be called once per test. Subsequent calls will throw an exception.
59
+
/// Only final states are allowed: Passed, Failed, Skipped, Timeout, or Cancelled. Intermediate states like Running, Queued, NotStarted, or WaitingForDependencies are rejected.
59
60
/// The original exception (if any) is preserved in <see cref="TestResult.OriginalException"/>.
61
+
/// When overriding to Failed, the original exception is retained in <see cref="TestResult.Exception"/>.
62
+
/// When overriding to Passed or Skipped, the Exception property is cleared but preserved in OriginalException.
60
63
/// Best practice: Call this from <see cref="ITestEndEventReceiver.OnTestEnd"/> or After(Test) hooks.
61
64
/// </remarks>
62
65
/// <example>
63
66
/// <code>
67
+
/// // Override failed test to passed
64
68
/// public class RetryOnInfrastructureErrorAttribute : Attribute, ITestEndEventReceiver
65
69
/// {
66
70
/// public ValueTask OnTestEnd(TestContext context)
67
71
/// {
68
72
/// if (context.Result?.Exception is HttpRequestException)
69
73
/// {
70
-
/// context.Execution.OverrideResult("Infrastructure error - not a test failure");
74
+
/// context.Execution.OverrideResult(TestState.Passed, "Infrastructure error - not a test failure");
71
75
/// }
72
76
/// return default;
73
77
/// }
74
78
/// public int Order => 0;
75
79
/// }
76
-
/// </code>
77
-
/// </example>
78
-
voidOverrideResult(stringreason);
79
-
80
-
/// <summary>
81
-
/// Overrides the test result with a specific state and custom reason.
82
-
/// </summary>
83
-
/// <param name="state">The desired test state (Passed, Failed, Skipped, Timeout, or Cancelled)</param>
84
-
/// <param name="reason">The reason for overriding the result (cannot be empty)</param>
85
-
/// <exception cref="ArgumentException">Thrown when reason is empty, whitespace, or state is invalid (NotStarted, WaitingForDependencies, Queued, Running)</exception>
86
-
/// <exception cref="InvalidOperationException">Thrown when result has already been overridden</exception>
87
-
/// <remarks>
88
-
/// This method can only be called once per test. Subsequent calls will throw an exception.
89
-
/// Only final states are allowed: Passed, Failed, Skipped, Timeout, or Cancelled. Intermediate states like Running, Queued, NotStarted, or WaitingForDependencies are rejected.
90
-
/// The original exception (if any) is preserved in <see cref="TestResult.OriginalException"/>.
91
-
/// When overriding to Failed, the original exception is retained in <see cref="TestResult.Exception"/>.
92
-
/// When overriding to Passed or Skipped, the Exception property is cleared but preserved in OriginalException.
93
-
/// Best practice: Call this from <see cref="ITestEndEventReceiver.OnTestEnd"/> or After(Test) hooks.
94
-
/// </remarks>
95
-
/// <example>
96
-
/// <code>
80
+
///
81
+
/// // Override failed test to skipped
97
82
/// public class IgnoreOnWeekendAttribute : Attribute, ITestEndEventReceiver
98
83
/// {
99
84
/// public ValueTask OnTestEnd(TestContext context)
0 commit comments