TestKit Core
A flexible and ergonomic database testing framework for Rust applications.
Key Features
- Simple API for common database testing patterns
- Composable Handlers for more complex scenarios
- Async/Await support for modern Rust applications
- Multiple Database Backends support
Simplified API
The simplified API provides straightforward functions for common database testing patterns:
// Just initialize a test database
let ctx = test_db.await?;
// Initialize a test database and run setup code
let ctx = test_db_with_setup.await?;
// Initialize a test database and run a transaction
let ctx = test_db_with_transaction.await?;
// Initialize a test database, run setup, then run a transaction
let ctx = test_db_with_setup_and_transaction.await?;
// Run a function with a database connection
let result = with_connection.await?;
Advanced Usage with Handlers
For more complex scenarios, you can use the composable handler API:
// Create a database entry point
let handler = with_database;
// Setup the database
let handler = handler.setup;
// Add a transaction
let handler = handler.with_transaction;
// Execute the handler chain
let ctx = handler.execute.await?;
Macro Usage
The testkit
crate also provides a macro for creating test fixtures:
```rust
// Create a database entry point
let handler = with_database!
.setup!
.with_transaction!.execute.await.unwrap;
Error Handling
All functions return Result<TestContext<DB>, Error>
or Result<T, Error>
where appropriate, allowing for proper error handling in your tests.