Available on crate feature
test
only.Expand description
Utilities for testing application.
§Example
use salvo_core::prelude::*;
#[handler]
async fn hello() -> &'static str {
"Hello"
}
fn route() -> Router {
Router::new().goal(hello)
}
#[tokio::main]
async fn main() {
let acceptor = TcpListener::new("0.0.0.0:5800").bind().await;
Server::new(acceptor).serve(route()).await;
}
#[cfg(test)]
mod tests {
use salvo_core::prelude::*;
use salvo_core::test::{ResponseExt, TestClient};
#[tokio::test]
async fn test_hello() {
let service = Service::new(super::route());
let content = TestClient::get("http://0.0.0.0:5800/")
.send(&service)
.await
.take_string()
.await
.unwrap();
assert!(content.contains("Hello"));
}
}
Structs§
- Request
Builder - The main way of building
Request
. - Test
Client - A type that can carry settings over multiple requests. The settings applied to the
TestClient
are applied to every request created from thisTestClient
.
Traits§
- Response
Ext - More utils functions for
Response
. - Send
Target - Trait for sending request to target, such as
Router
,Service
,Handler
for test usage.