Entity Framework Core Interview Question #180
How can database tests be isolated from each other?
Testing, Production Practices & Senior Real-World Scenarios Senior Advanced
Quick Interview Answer
Each test should start from a known state and should not depend on execution order. Isolation can be achieved with a fresh database, transaction rollback, schema reset, database respawn strategies, or separate containers/databases. The chosen technique must match the provider and test parallelism requirements.
Detailed Explanation
Each test should start from a known state and should not depend on execution order. Isolation can be achieved with a fresh database, transaction rollback, schema reset, database respawn strategies, or separate containers/databases. The chosen technique must match the provider and test parallelism requirements.
Code Example
// Arrange known data -> execute test -> clean/reset.
// Never rely on data left by a previous test.