
This is for spinning up an Axum service, that you can then query directly.
This is primarily for testing Axum services.
use ::axum::Router;
use ::axum::routing::get;
use ::axum_test_server::TestServer;
async fn get_ping() -> &'static str {
"pong!"
}
#[tokio::test]
async fn it_sound_get() {
let app = Router::new()
.route("/ping", get(get_ping))
.into_make_service();
let server = TestServer::new_with_random_address(app);
let response = server
.get("/ping")
.await
.assert_contents(&"pong!");
assert_eq!(response.contents, "pong!");
}
One of the main benefits is you can spin up the server on a random port,
allowing you to run multiple servers in parallel.