axum-test-helpers

🧪 Test client for axum copied from axum

3 releases

0.7.6 Sep 25, 2024
0.7.5 Feb 10, 2024
0.7.4 Feb 10, 2024

#268 in Testing

Download history 3/week @ 2024-06-15 6/week @ 2024-06-22 1/week @ 2024-06-29 7/week @ 2024-07-06 21/week @ 2024-07-13 35/week @ 2024-07-20 31/week @ 2024-07-27 22/week @ 2024-08-03 8/week @ 2024-08-10 6/week @ 2024-08-17 12/week @ 2024-08-24 16/week @ 2024-08-31 22/week @ 2024-09-07 52/week @ 2024-09-14 191/week @ 2024-09-21 41/week @ 2024-09-28

307 downloads per month
Used in 2 crates

GPL-3.0-only

17KB
253 lines

axum-test-helpers

axum-test-helpers exposes axum original TestClient, which is private to the axum crate

More information about this crate can be found in the crate documentation.

High level features

  • Provide an easy to use interface
  • Start a server in a different port for each call
  • Deal with JSON, text and files response/requests

Usage example

Add this crate as a dev-dependency:

[dev-dependencies]
axum-test-helpers = "0.7.4"

Use the TestClient on your own Router:

use axum::Router;
use axum::http::StatusCode;
use axum_test_helper::TestClient;

// you can replace this Router with your own app
let app = Router::new().route("/", get(|| async {}));

// initiate the TestClient with the previous declared Router
let client = TestClient::new(app);
let res = client.get("/").await;
assert_eq!(res.status(), StatusCode::OK);

You can find examples like this in the example directory.

See the crate documentation for way more examples.

Disable trace

By default axum-test-helpers print trace like Listening on 127.0.0.1:36457. You can disable trace with axum-test-helpers = { version = "0.*", default-features = false, features = ["withouttrace"] }.

Contributing

Before submitting a pull request or after pulling from the main repository, ensure all tests pass:

# Run axum-test-helpers tests
cargo test

# Test the hello-world example project
(cd examples/hello-world && cargo test)

License

This project is licensed under the GPL-3.0-only.

Dependencies

~8–20MB
~297K SLoC