6 releases (3 breaking)

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

#117 in Testing

Download history 4818/week @ 2024-07-26 5912/week @ 2024-08-02 6175/week @ 2024-08-09 5444/week @ 2024-08-16 4411/week @ 2024-08-23 5978/week @ 2024-08-30 4783/week @ 2024-09-06 2244/week @ 2024-09-13 3203/week @ 2024-09-20 4468/week @ 2024-09-27 2874/week @ 2024-10-04 3261/week @ 2024-10-11 2855/week @ 2024-10-18 2455/week @ 2024-10-25 3696/week @ 2024-11-01 3227/week @ 2024-11-08

12,897 downloads per month
Used in 6 crates

MIT license

13KB
195 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"] }.

Contributing

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

# Run axum-test-helper tests
cargo test

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

License

This project is licensed under the MIT license.

Dependencies

~9–24MB
~305K SLoC