Function actix_http_test::test_server
source · pub async fn test_server<F: ServerServiceFactory<TcpStream>>(
factory: F
) -> TestServer
Expand description
Start test server.
TestServer
is very simple test server that simplify process of writing integration tests cases
for HTTP applications.
Examples
use actix_http::HttpService;
use actix_http_test::test_server;
use actix_web::{web, App, HttpResponse, Error};
async fn my_handler() -> Result<HttpResponse, Error> {
Ok(HttpResponse::Ok().into())
}
#[actix_web::test]
async fn test_example() {
let mut srv = TestServer::start(||
HttpService::new(
App::new().service(web::resource("/").to(my_handler))
)
);
let req = srv.get("/");
let response = req.send().await.unwrap();
assert!(response.status().is_success());
}