-
-
Notifications
You must be signed in to change notification settings - Fork 0
testing
NestForge includes a testing module builder through the optional testing feature.
nestforge = { version = "1", features = ["testing"] }let module = nestforge::TestFactory::<AppModule>::create()
.override_provider(AppConfig {
app_name: "test",
})
.build()?;The built TestingModule can still resolve providers directly:
let config = module.resolve::<AppConfig>()?;When a test finishes with modules that own cleanup work, call:
module.shutdown()?;That runs module destroy and application shutdown lifecycle hooks inside the testing runtime.
TestingModule::http_router() merges the module controllers into a ready-to-test Axum router with the framework container attached as state.
let app = module.http_router();This is useful for request-level tests with tower::ServiceExt::oneshot(...).
TestingModule::graphql_router(...) and TestingModule::graphql_router_with_paths(...) mount a schema into the same testing container:
let schema = Schema::build(QueryRoot, EmptyMutation, EmptySubscription).finish();
let app = module.graphql_router(schema);That lets GraphQL resolvers resolve the same providers and overrides as the rest of the test module.
TestingModule can also create transport contexts directly for lower-level tests:
let grpc = module.grpc_context();
let websocket = module.websocket_context();
let microservice = module.microservice_context("test", "users.count");Use these helpers when you want to test gRPC services, websocket gateways, or transport-neutral message handlers without booting the full transport server.
It can also build an in-process microservice client for request/emit style tests:
use nestforge::MicroserviceClient;
let client = module.microservice_client(registry);
let count: usize = client.send("users.count", ()).await?;NestForge Docs | Home | Quick Start | Project Structure | GitHub Repo