pub struct TestAppBuilder { /* private fields */ }Expand description
Builder for in-memory test applications.
Use the builder when tests need provider overrides, request-scoped providers, config overrides, or lifecycle hooks in addition to an Axum router.
Implementations§
Source§impl TestAppBuilder
impl TestAppBuilder
Sourcepub fn transient_provider<T, F>(self, factory: F) -> Result<Self>
pub fn transient_provider<T, F>(self, factory: F) -> Result<Self>
Registers a transient provider factory in the test container.
Sourcepub fn request_provider<T, F>(self, factory: F) -> Result<Self>
pub fn request_provider<T, F>(self, factory: F) -> Result<Self>
Registers a request-lifetime provider factory in the test container.
Sourcepub fn request_scoped_provider<T, F>(self, factory: F) -> Result<Self>
pub fn request_scoped_provider<T, F>(self, factory: F) -> Result<Self>
Registers a request-lifetime provider factory that resolves dependencies through the active request scope.
This matches production request-scoped resolution. To exercise
RequestScoped<T> extractors over HTTP in the test app, also call
TestAppBuilder::with_request_scope so the request scope layer is
installed on the router.
Sourcepub fn with_request_scope(self) -> Self
pub fn with_request_scope(self) -> Self
Installs the production request scope layer so RequestScoped<T>
extractors resolve during HTTP integration tests.
Without this, handlers that extract RequestScoped<T> reject with
500/request_scope_unavailable. Register request providers with
Self::request_provider or Self::request_scoped_provider first.
Sourcepub fn override_provider<T>(self, value: T) -> Result<Self>
pub fn override_provider<T>(self, value: T) -> Result<Self>
Overrides a provider in the test container.
Sourcepub fn config(self, config: Config) -> Self
pub fn config(self, config: Config) -> Self
Sets configuration overrides for the test application.
Sourcepub fn lifecycle_hook<H>(self, hook: H) -> Selfwhere
H: LifecycleHook,
pub fn lifecycle_hook<H>(self, hook: H) -> Selfwhere
H: LifecycleHook,
Registers a lifecycle hook for the test application.
Sourcepub async fn build_started(self) -> Result<TestApp>
pub async fn build_started(self) -> Result<TestApp>
Runs startup hooks and builds the test application.