-
-
Notifications
You must be signed in to change notification settings - Fork 108
Closed
Description
Info
- IDE: JetBrains Rider 2025.2.4
- TUnit version: 1.3.15
Recreation of the problem
I have a single test class that implements IAsyncInitializer resource. The initializer is called two times per usage class regardless of whether only one test class is run.
public sealed class BugResource : IAsyncInitializer, IAsyncDisposable
{
public static int TearDowns = 0;
public static int SetUps = 0;
public ValueTask DisposeAsync()
{
Interlocked.Increment(ref TearDowns);
return ValueTask.CompletedTask;
}
public Task InitializeAsync()
{
Interlocked.Increment(ref SetUps);
return Task.CompletedTask;
}
}
public sealed class BugTestTwo
{
[ClassDataSource<BugResource>]
public required BugResource BugResource { get; init; }
[Test]
public async Task TestTwo)
{
await Assert.That(BugResource.SetUps).EqualTo(1);
}
}
public sealed class BugTestThree
{
[ClassDataSource<BugResource>]
public required BugResource BugResource { get; init; }
[Test]
public async Task TestThree()
{
await Assert.That(BugResource.SetUps).EqualTo(1);
}
}
public sealed class BugTestOne
{
[ClassDataSource<BugResource>]
public required BugResource BugResource { get; init; }
[Test]
public async Task TestOne()
{
await Assert.That(BugResource.SetUps).EqualTo(1);
}
} That is, running any of BugTestN results in 2 calls to InitializeAsync. However, if I run a session with all three, then InitializeAsync is called 6 times.
What would solve my problem
The InitializeAsync should only be called once per test class, so in a session with all three test classes it should be called 3 times.
Metadata
Metadata
Assignees
Labels
No labels