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, Response, Error, StatusCode};
use actix_http_test::test_server;
use actix_service::{fn_service, map_config, ServiceFactoryExt as _};
#[actix_rt::test]
async fn test_example() {
let srv = test_server(|| {
HttpService::build()
.h1(fn_service(|req| async move {
Ok::<_, Error>(Response::ok())
}))
.tcp()
.map_err(|_| ())
})
.await;
let req = srv.get("/");
let response = req.send().await.unwrap();
assert_eq!(response.status(), StatusCode::OK);
}