5 unstable releases

0.3.0 Jun 3, 2023
0.2.0 Dec 19, 2022
0.1.2 Dec 19, 2022
0.1.1 Jul 3, 2022
0.1.0 Apr 28, 2022

#291 in Testing

Download history 1223/week @ 2024-01-15 1234/week @ 2024-01-22 1476/week @ 2024-01-29 1315/week @ 2024-02-05 1478/week @ 2024-02-12 1415/week @ 2024-02-19 1751/week @ 2024-02-26 1885/week @ 2024-03-04 2012/week @ 2024-03-11 1953/week @ 2024-03-18 1804/week @ 2024-03-25 2031/week @ 2024-04-01 1446/week @ 2024-04-08 1880/week @ 2024-04-15 2465/week @ 2024-04-22 1759/week @ 2024-04-29

7,655 downloads per month
Used in 3 crates

MIT license

12KB
187 lines

axum-test-helper

axum-test-helper 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-helper = "0.*" # alternatively specify the version as "0.3.0"

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("/").send().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-helper print trace like Listening on 127.0.0.1:36457. You can disable trace with axum-test-helper = { version = "0.*", default-features = false, features = ["withouttrace"] }.

License

This project is licensed under the MIT license.

Dependencies

~8–21MB
~326K SLoC