Skip to content

Commit 3c94b16

Browse files
authored
fix: skip tests when transitive dependencies fail (#4646)
Fixes #4643 When Test3 depends on Test2, which depends on Test1, and Test1 fails: - Test2 is correctly skipped (direct dependency) - Test3 was incorrectly running instead of being skipped Changed TestRunner to skip tests when dependencies have any non-Passed state (Failed, Skipped, Timeout, Cancelled), not just Failed state. This ensures transitive dependencies are properly handled. Changes: - Updated TestRunner.cs condition from `State == TestState.Failed` to `State != TestState.Passed` - Added TransitiveDependenciesTests to reproduce and verify the fix
1 parent a77e3bf commit 3c94b16

3 files changed

Lines changed: 61 additions & 1 deletion

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using Shouldly;
2+
using TUnit.Engine.Tests.Enums;
3+
4+
namespace TUnit.Engine.Tests;
5+
6+
/// <summary>
7+
/// Verifies that tests are correctly skipped when transitive dependencies fail.
8+
/// Tests the fix for GitHub issue #4643.
9+
/// </summary>
10+
public class TransitiveDependenciesTests(TestMode testMode) : InvokableTestBase(testMode)
11+
{
12+
[Test]
13+
public async Task Test()
14+
{
15+
await RunTestsWithFilter(
16+
"/*/*/TransitiveDependenciesTests/*",
17+
[
18+
result => result.ResultSummary.Outcome.ShouldBe("Failed"),
19+
result => result.ResultSummary.Counters.Total.ShouldBe(3),
20+
result => result.ResultSummary.Counters.Passed.ShouldBe(0),
21+
result => result.ResultSummary.Counters.Failed.ShouldBe(1), // Only Test1 should fail
22+
result => result.ResultSummary.Counters.NotExecuted.ShouldBe(2) // Test2 and Test3 should be skipped
23+
]);
24+
}
25+
}

TUnit.Engine/Scheduling/TestRunner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ private async ValueTask ExecuteTestInternalAsync(AbstractExecutableTest test, Ca
7878
{
7979
await ExecuteTestAsync(dependency.Test, cancellationToken).ConfigureAwait(false);
8080

81-
if (dependency.Test.State == TestState.Failed && !dependency.ProceedOnFailure)
81+
if (dependency.Test.State != TestState.Passed && !dependency.ProceedOnFailure)
8282
{
8383
_testStateManager.MarkSkipped(test, "Skipped due to failed dependencies");
8484
await _tunitMessageBus.Skipped(test.Context, "Skipped due to failed dependencies").ConfigureAwait(false);
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using TUnit.TestProject.Attributes;
2+
3+
namespace TUnit.TestProject;
4+
5+
/// <summary>
6+
/// Tests for transitive dependency handling when dependencies fail.
7+
/// Reproduces GitHub issue #4643: Tests not skipped when transitive dependencies fail
8+
/// </summary>
9+
[EngineTest(ExpectedResult.Failure)]
10+
public class TransitiveDependenciesTests
11+
{
12+
[Test]
13+
public async Task Test1()
14+
{
15+
// This test fails intentionally
16+
await Assert.That(true).IsEqualTo(false);
17+
}
18+
19+
[Test, DependsOn(nameof(Test1))]
20+
public async Task Test2()
21+
{
22+
// Test2 depends on Test1, which fails
23+
// Test2 should be skipped
24+
await Assert.That(true).IsEqualTo(false);
25+
}
26+
27+
[Test, DependsOn(nameof(Test2))]
28+
public async Task Test3()
29+
{
30+
// Test3 depends on Test2, which depends on Test1
31+
// When Test1 fails, Test2 is skipped
32+
// Therefore Test3 should also be skipped (transitive dependency)
33+
await Assert.That(true).IsEqualTo(false);
34+
}
35+
}

0 commit comments

Comments
 (0)