Using this library, you can host your application and query against it with requests. Then decode the responses, and assert what is returned.
use Router;
use get;
use TestServer;
async
async
The TestServer can run requests directly against your application with a mocked network,
or the application can run on a random port (with real network reqeusts being made).
In both cases allowing multiple servers to run in parallel, across your tests.
This behaviour can be changed in the TestServerConfig, by selecting the transport to be used.
Axum Compatability
Axum Test requires the latest version of Axum (0.7).
| Axum Version | Axum Test Version |
|---|---|
| 0.7 (latest) | 14, 15+ (latest) |
| 0.6 | 13.4.1 |
Crate Features
Here are a list of all features so far that can be enabled:
alloff by default, turns on all features below.pretty-assertionson by default, uses the pretty assertions crate for the output to theassert_*functions.yamloff by default, adds support for sending, receiving, and asserting, yaml content.msgpackoff by default, adds support for sending, receiving, and asserting, msgpack content.shuttleoff by default, adds support for building aTestServerfromshuttle_axum::AxumService, for use with Shuttle.rs.typed-routingoff by default, adds support for theTypedPathfrom axum-extra.wsoff by default, adds support for WebSockets.
Examples
You can find examples of writing tests in the /examples folder. These include tests for:
- a REST Todo application
- a WebSocket ping pong application which sends requests up and down
- a simple WebSocket chat application
Request Building Features
Querying your application on the TestServer supports all of the common request building you would expect.
- Serializing and deserializing Json and Form content using Serde
- Cookie setting and reading
- Access to setting and reading headers
- Status code reading and assertions
- Assertions for defining what you expect to have returned
- Upgrading a connection for use with WebSockets
It also includes
- Saving cookies returned for use across future requests
- Setting headers and query parameters for use across all TestRequests
- Can optionally run requests using a real web server
- Automatic status assertions for checking requests always succeed or fail
- Prettifying the assertion output
- Typed Routing from Axum Extra
Contributions
A big thanks to all of these who have helped!
Made with contrib.rocks.