Orchestration โ
Managing complex test infrastructureโlike databases, message brokers, and external APIsโis a common challenge in integration testing. Prova provides several tools to help orchestrate these dependencies.
Lifecycle Hooks โ
Use lifecycle hooks to manage the setup and teardown of shared infrastructure.
[BeforeAll]/[AfterAll]: Perfect for global infrastructure that should persist across all tests in a class or assembly.[BeforeEach]/[AfterEach]: Use these for state that must be reset for every single test.
csharp
public class DatabaseTests : IAsyncLifetime
{
private MyDb _db;
public async Task InitializeAsync()
{
_db = await Container.StartSqlAsync();
}
public async Task DisposeAsync()
{
await _db.StopAsync();
}
}Service Discovery โ
Prova integrates tightly with dependency injection, allowing you to easily resolve services needed for your tests.
[ClassFactory]: Use a custom factory to instantiate your test classes with complex dependencies.[ClassDataSource]: Inject data directly into your test class constructors from DI.
Integration Tools โ
Prova ecosystem includes first-class support for industry-standard orchestration tools.
- Testcontainers: Use the
Prova.Testcontainerspackage to spin up transient Docker containers for databases and other services. - .NET Aspire: Leverage the
Aspire.Hosting.Testinglibrary to test multi-service applications as a single unit. - Playwright: Orchestrate browser instances for full end-to-end UI testing.
Test Isolation โ
To prevent flaky tests, ensure that each test run is isolated:
- Prefer Transient State: Use unique database schemas or ports for each test run where possible.
- Clean Teardown: Always use
IAsyncLifetimeor[AfterAll]to shut down resources, even if a test fails. - Handle Timeouts: Use the
[Timeout]attribute to ensure a hung orchestration step doesn't block your entire CI pipeline.