Skip to content

Commit 5cac489

Browse files
committed
feat(execution): Simplify exception handling in ExecuteAsync method for clearer test failure logic
1 parent cb202d7 commit 5cac489

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

TUnit.Engine/TestExecutor.cs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ public async Task ExecuteAsync(AbstractExecutableTest executableTest, Cancellati
6565
{
6666
await EnsureTestSessionHooksExecutedAsync().ConfigureAwait(false);
6767

68-
// Event receivers have their own internal coordination to run once
6968
await _eventReceiverOrchestrator.InvokeFirstTestInSessionEventReceiversAsync(
7069
executableTest.Context,
7170
executableTest.Context.ClassContext.AssemblyContext.TestSessionContext,
@@ -135,24 +134,17 @@ await TimeoutHelper.ExecuteWithTimeoutAsync(
135134
}
136135
}
137136

138-
// If test passed but hooks failed, throw hook exception to fail the test
139137
if (capturedException == null && hookException != null)
140138
{
141139
ExceptionDispatchInfo.Capture(hookException).Throw();
142140
}
143-
144-
// If test failed or was skipped, handle the test exception
145-
if (capturedException != null)
141+
else if (capturedException is SkipTestException)
146142
{
147-
if (capturedException is SkipTestException)
148-
{
149-
ExceptionDispatchInfo.Capture(capturedException).Throw();
150-
}
151-
152-
if (executableTest.Context.Execution.Result?.IsOverridden != true)
153-
{
154-
ExceptionDispatchInfo.Capture(capturedException).Throw();
155-
}
143+
ExceptionDispatchInfo.Capture(capturedException).Throw();
144+
}
145+
else if (capturedException != null && executableTest.Context.Execution.Result?.IsOverridden != true)
146+
{
147+
ExceptionDispatchInfo.Capture(capturedException).Throw();
156148
}
157149
}
158150

0 commit comments

Comments
 (0)