Function ntex_server::net::test_server
source · pub fn test_server<F, R>(factory: F) -> TestServer
Expand description
Start test server
TestServer
is very simple test server that simplify process of writing
integration tests cases for ntex web applications.
§Examples
use ntex::http;
use ntex::http::client::Client;
use ntex::server;
use ntex::web::{self, App, HttpResponse};
async fn my_handler() -> Result<HttpResponse, std::io::Error> {
Ok(HttpResponse::Ok().into())
}
#[ntex::test]
async fn test_example() {
let mut srv = server::test_server(
|| http::HttpService::new(
App::new().service(
web::resource("/").to(my_handler))
)
);
let req = Client::new().get("http://127.0.0.1:{}", srv.addr().port());
let response = req.send().await.unwrap();
assert!(response.status().is_success());
}