Quick Start
The simplest way to write a test with database support using Jest-like syntax:Jest-like Testing (Recommended)
Kit provides Jest-like macros for better test organization and clearer assertion output.The describe! Macro
Group related tests with descriptive names:
The test! Macro
Define individual test cases with three syntax options:
The expect! Macro
Fluent assertions with clear failure output:
Clear Failure Output
When an assertion fails, you get clear output with the test name:Testing Approaches (Traditional)
Kit also provides traditional ways to write database-enabled tests:1. Attribute Macro (Recommended)
The#[kit_test] attribute macro is the cleanest way to write tests:
2. Helper Macro
For more control, use thetest_database! macro:
How It Works
When you use#[kit_test]:
- Services Bootstrapped: All services marked with
#[injectable]are automatically registered, soApp::resolve::<T>()works just like in production - Fresh Database: A new in-memory SQLite database is created for each test
- Migrations Applied: Your
crate::migrations::Migratorruns automatically - Automatic Integration: The test database is registered in the DI container, so any code using
DB::connection()or#[inject] db: Databaseautomatically uses the test database - Complete Isolation: Each test is fully isolated - no data leaks between tests
The
#[kit_test] macro calls App::init() and App::boot_services() before your test runs, ensuring all injectable services are available.Testing Actions
Actions marked with#[injectable] can be resolved from the container in tests:
Custom Migrator
By default, both macros usecrate::migrations::Migrator. If your migrator is in a different location:
Direct Database Access
TheTestDatabase struct provides methods for direct database queries: