Repository navigation
Integration testing multiple Databases for same Tests #5436
Replies: 1 comment
|
Current TUnit can model this as multiple class data sources for one test-class constructor, which is closer to the requirement than injecting two databases into the same test instance. There is regression coverage on current [ClassDataSource(typeof(IntDataSource1))]
[ClassDataSource(typeof(IntDataSource2))]
public class ArgumentsWithClassDataSourceTests(int classArg)and TUnit verifies that the class/tests are instantiated once for each source (and, when combined with other class data, once for every supplied class case). For two database fixtures, the corresponding shape is: [ClassDataSource(typeof(PostgresFixture), Shared = SharedType.PerTestSession)]
[ClassDataSource(typeof(SqlServerFixture), Shared = SharedType.PerTestSession)]
public class DatabaseTests(IDatabaseFixture db)
{
[Test]
public async Task Same_contract_runs_for_each_database()
{
// test only against db
}
}where both fixture types are compatible with the constructor parameter. This gives each generated test-class case one database fixture, so the same tests execute independently against each implementation. It is different from The current sharing semantics are also worth keeping: If the two fixtures need different construction logic or cannot share a constructor abstraction, a method/custom data source that yields a common wrapper is another option. But for “same contract tests, two interchangeable database implementations”, multiple class-level |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I have a Project wich should support two Databases using Ef core.
Is it possible to run the same Tests for different Databases?
I am currently using the
ClassDataSource<T>(Shared = PerTestSession)Attribute to provide an TestContianer Database to the Baseclass of the tests.Is there a way to run the tests also with a different Db (parallel or not, trying to use the Attribute a second time does not work.
All reactions