diff --git a/TUnit.Engine.Tests/HookExecutionOrderTests.cs b/TUnit.Engine.Tests/HookExecutionOrderTests.cs index 65dc6cf001..d3d670b805 100644 --- a/TUnit.Engine.Tests/HookExecutionOrderTests.cs +++ b/TUnit.Engine.Tests/HookExecutionOrderTests.cs @@ -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>("executionOrder", _ => []); + order.Add("BeforeEvery"); } } public class HookExecutionOrderTests { - internal static readonly List _executionOrder = []; - [Before(Test)] public void InstanceSetup() { - _executionOrder.Add("Before"); + var order = TestContext.Current!.StateBag.GetOrAdd>("executionOrder", _ => []); + order.Add("Before"); } [Test] public void VerifyExecutionOrder() { - _executionOrder.Add("Test"); + var order = TestContext.Current!.StateBag.GetOrAdd>("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"); } }