Function ntex::http::test::server

source ·
pub fn server<F, R>(factory: F) -> TestServer
where F: Fn() -> R + Send + Clone + 'static, R: ServiceFactory<Io> + 'static,
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::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 = http::test::server(
        || http::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());
}