-
-
Notifications
You must be signed in to change notification settings - Fork 108
Closed
Description
Description
In 0.50.x, IFirstTestInAssemblyEventReceiver.OnFirstTestInAssembly is invoked twice before any tests start, while [Before(Assembly)] runs exactly once. This reproduces with the minimal sample below. On 0.25.21 both were called exactly once.
Environment
- TUnit: 0.50.x (after Fix first event receiver thread safety using GetOnlyDictionary + Task pattern #2917 fix)
- macOS 15.5 (arm64)
- .NET: 9.0
- IDE: Rider
Test Code
using TUnit.Core;
using TUnit.CoreHooks;
using TUnit.Core.Tests;
namespace GNS.TUNIT_LAB;
public class CallEventReceiverTests : IFirstTestInAssemblyEventReceiver
{
private static int tmp = 1;
[Test]
public async Task Test1()
{
var result = true;
await Assert.That(result).IsTrue();
}
[Test]
public async Task Test2()
{
var result = true;
await Assert.That(result).IsTrue();
}
[Before(Assembly)]
public static void Before_assembly()
{
tmp++;
Console.WriteLine($"Before_assembly tmp={tmp}");
}
public ValueTask OnFirstTestInAssembly(AssemblyHookContext context, TestContext testContext)
{
tmp++;
Console.WriteLine($"OnFirstTestInAssembly tmp={tmp}");
return ValueTask.CompletedTask;
}
}Steps to Reproduce
- Run the test class above with TUnit 0.50.x.
- Observe console output or set breakpoints in both Before_assembly and OnFirstTestInAssembly.
Expected Behavior
- OnFirstTestInAssembly is called exactly once per assembly, and before any test runs.
- [Before(Assembly)] is also called exactly once, before tests.
Actual Behavior (0.50.x)
- OnFirstTestInAssembly is invoked twice before any tests start.
- [Before(Assembly)] is invoked once.
- This differs from 0.25.21, where each was invoked once.
Notes
- I will attach a GIF showing the two invocations of OnFirstTestInAssembly before test execution.
- This seems related to the thread-safety change in Fix first event receiver thread safety using GetOnlyDictionary + Task pattern #2917 but still results in duplicate assembly-first calls.
Requests
- Restore the exactly-once-per-assembly guarantee for IFirstTestInAssemblyEventReceiver before test execution.
- Clarify the documented ordering guarantees between OnFirstTestInAssembly and [Before(Assembly)].
Copilot
Metadata
Metadata
Assignees
Labels
No labels
