axum-test-server

Crates.ioaxum-test-server
lib.rsaxum-test-server
version2.0.0
created_at2023-01-12 17:25:44.977113+00
updated_at2023-01-17 23:15:31.66315+00
descriptionFor spinning up and testing Axum servers
homepage
repositoryhttps://github.com/JosephLenton/axum-test-server
max_upload_size
id757350
size17,087
Joseph Lenton (JosephLenton)

documentation

https://docs.rs/axum-test-server/latest/axum-test-server

README

Axum Test Server
for testing Axum Servers

crate docs

This has been moved to Axum Test, and you can find it here.

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() {
      // Build an application with a route.
      let app = Router::new()
          .route("/ping", get(get_ping))
          .into_make_service();

      // Run the server.
      let server = TestServer::new_with_random_address(app);

      // Get the request.
      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.

Commit count: 153

cargo fmt