Skip to content
Merged
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
25 changes: 15 additions & 10 deletions TUnit.Engine.Tests/HookExecutionOrderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,35 @@ public sealed class GlobalHookExecutionOrderSetup
[BeforeEvery(Test)]
public static void GlobalSetup(TestContext context)
{
HookExecutionOrderTests._executionOrder.Clear(); // Clear before each test
HookExecutionOrderTests._executionOrder.Add("BeforeEvery");
if (context.Metadata.TestDetails.ClassType != typeof(HookExecutionOrderTests))
{
return;
}

var order = context.StateBag.GetOrAdd<List<string>>("executionOrder", _ => []);
order.Add("BeforeEvery");
}
}

public class HookExecutionOrderTests
{
internal static readonly List<string> _executionOrder = [];

[Before(Test)]
public void InstanceSetup()
{
_executionOrder.Add("Before");
var order = TestContext.Current!.StateBag.GetOrAdd<List<string>>("executionOrder", _ => []);
order.Add("Before");
}

[Test]
public void VerifyExecutionOrder()
{
_executionOrder.Add("Test");
var order = TestContext.Current!.StateBag.GetOrAdd<List<string>>("executionOrder", _ => []);
order.Add("Test");

// Verify that BeforeEvery runs before Before
_executionOrder.Count.ShouldBe(3);
_executionOrder[0].ShouldBe("BeforeEvery");
_executionOrder[1].ShouldBe("Before");
_executionOrder[2].ShouldBe("Test");
order.Count.ShouldBe(3);
order[0].ShouldBe("BeforeEvery");
order[1].ShouldBe("Before");
order[2].ShouldBe("Test");
}
}
Loading