Skip to main content

Module testing

Module testing 

Source
Expand description

In-process test harness.

TestClient drives an application without a network: it builds the app (running the lifespan), then sends requests straight through the request pipeline and reads responses, with helpers for JSON, forms, file uploads, Server-Sent Events, and WebSockets. It can also override resources and dependencies, hold a cookie jar and default headers, and run the lifespan shutdown when finished.

Structsยง

LogRecord
A single captured log record.
LogRecorder
Captures log records for assertions in tests.
TestClient
An in-process client for exercising an application in tests.
TestClientBuilder
A builder for a TestClient with resource and dependency overrides, default headers, and seeded cookies.
TestMultipartBuilder
Builds and sends a multipart/form-data request (forms with files).
TestRequestBuilder
Builds and sends a single HTTP request.
TestResponse
A buffered response captured by the TestClient.
TestSseEvent
A single event parsed from a Server-Sent Events stream.
TestSseStream
A reader over a text/event-stream response body.
TestWebSocket
An open WebSocket connection in a test.
TestWebSocketBuilder
Builds a WebSocket connection: set headers, query parameters, and subprotocols, then call connect.