Skip to content

IFirstTestInAssemblyEventReceiver is invoked twice before any tests run in 0.50.x #2951

@candhub

Description

@candhub

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

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

  1. Run the test class above with TUnit 0.50.x.
  2. 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

Requests

  • Restore the exactly-once-per-assembly guarantee for IFirstTestInAssemblyEventReceiver before test execution.
  • Clarify the documented ordering guarantees between OnFirstTestInAssembly and [Before(Assembly)].

Image

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions