I've been banging my hand on a wall with this one, and I finally found a workaround.
I have two fixtures, one for creating/seeding a DB, the other to have different contexts.
Following the documentation, I tried using ClassDataSource like this:
using TUnit.Core;
using TUnit.Core.Interfaces;
namespace DebugTests;
public class Fixture1 : IAsyncInitializer
{
public async Task InitializeAsync()
{
Console.WriteLine("Fixture1 InitializeAsync");
await Task.Delay(2);
}
}
public class Fixture2 : IAsyncInitializer
{
public async Task InitializeAsync()
{
Console.WriteLine("Fixture2 InitializeAsync");
await Task.Delay(2);
}
}
[ClassDataSource<Fixture1, Fixture2>(Shared = [SharedType.Globally, SharedType.Globally])]
public class Tests(Fixture1 fix1, Fixture2 fix2)
{
[Test]
public async Task Test1()
{
Console.WriteLine("Tests.Test1");
await Task.Delay(2);
}
}
This results in neither of the InitializeAsync logs showing up. Using a single parameter works as intended though.
I thus used this workaround:
public class Tests
{
[ClassDataSource<Fixture1>(Shared = SharedType.Globally)]
public required Fixture1 fix1 {get; init;}
[ClassDataSource<Fixture2>(Shared = SharedType.Globally)]
public required Fixture2 fix2 {get; init;}
// [...]
}
I don't see any reason why the former shouldn't work.
Have I misunderstood something?
PS: there are some discrepancies in the doc, e.g. BeforeEvery is not documented, nor is the fact that methods using those attributes must all be static.
Hello,
I've been banging my hand on a wall with this one, and I finally found a workaround.
I have two fixtures, one for creating/seeding a DB, the other to have different contexts. Following the documentation, I tried using
ClassDataSource
like this:This results in neither of the
InitializeAsync
logs showing up. Using a single parameter works as intended though.I thus used this workaround:
I don't see any reason why the former shouldn't work. Have I misunderstood something?
PS: there are some discrepancies in the doc, e.g.
BeforeEvery
is not documented, nor is the fact that methods using those attributes must all be static.