This runs your application locally, allowing you to query against it with requests. Decode the responses, and assert what is returned.
use Router;
use get;
use TestServer;
async
A TestServer enables you to run an Axum service with a mocked network,
or on a random port with real network reqeusts.
In both cases allowing you to run multiple servers, across multiple tests, all in parallel.
🎁 Crate Features
| Feature | On by default | |
|---|---|---|
all |
off | Turns on all non-deprecated features. |
pretty-assertions |
on | Uses the pretty assertions crate on response assert_* methods. |
yaml |
off | Enables support for sending, receiving, and asserting, yaml content. |
msgpack |
off | Enables support for sending, receiving, and asserting, msgpack content. |
typed-routing |
off | Enables support for using TypedPath in requests. See axum-extra for details. |
ws |
off | Enables WebSocket support. See TestWebSocket for details. |
reqwest |
off | Enables the TestServer being able to create Reqwest requests for querying. |
Deprecated
| Feature | On by default | |
|---|---|---|
old-json-diff |
off | Switches back to the old Json diff behaviour before Axum Test 18. If you find yourself needing this, then please raise an issue to let me know why. |
⚙️ Axum Compatibility
The current version of Axum Test requires at least Axum v0.8.7.
Here is a list of compatability with prior versions:
| Axum Version | Axum Test Version |
|---|---|
| 0.8.7+ (latest) | 18.3.0 (latest) |
| 0.8.4 | 18.0.0 |
| 0.8.3 | 17.3 |
| 0.8.0 | 17 |
| 0.7.6 to 0.7.9 | 16 |
| 0.7.0 to 0.7.5 | 14, 15 |
| 0.6 | 13.4.1 |
📺 Examples
You can find examples of writing tests in the /examples folder. These include tests for:
- a simple REST Todo application
- a WebSocket ping pong application which sends requests up and down
- a simple WebSocket chat application
- example snapshot tests using Insta
🚀 Request Building Features
Querying your application on the TestServer supports all of the common request building you would expect.
- Serializing and deserializing Json, Form, Yaml, and others, using Serde
- Assertions on the Json, text, Yaml, etc, that is returned.
- Cookie, query, and header setting and reading
- Status code reading and assertions
Powerful Json assertions
The ability to assert only the shape of the Json returned:
use TestServer;
use expect_json;
use Duration;
// Your application
let app = new
.route;
let server = new?;
server.get
.await
.assert_json;
Docs:
Also includes
- WebSockets testing support
- Saving returned cookies for use on future requests
- Setting headers, query, and cookies, globally for all requests or on per request basis
- Can run requests using a real web server, or with mocked HTTP
- Automatic status assertions for expecting requests to succeed (to help catch bugs in tests sooner)
- Prettified assertion output
- Typed Routing from Axum Extra
- Reqwest integration
❤️ Contributions
A big thank you to all of these who have helped!
Made with contrib.rocks