[][src]Function ntex::web::test::server

pub fn server<F, I, S, B>(factory: F) -> TestServer where
    F: Fn() -> I + Send + Clone + 'static,
    I: IntoServiceFactory<S>,
    S: ServiceFactory<Config = AppConfig, Request = Request> + 'static,
    S::Error: ResponseError + 'static,
    S::InitError: Debug,
    S::Response: Into<HttpResponse<B>> + 'static,
    <S::Service as Service>::Future: 'static,
    B: MessageBody + 'static, 

Start test server with default configuration

Test server is very simple server that simplify process of writing integration tests cases for ntex web applications.

Examples

use ntex::web::{self, test, App, HttpResponse};

async fn my_handler() -> Result<HttpResponse, std::io::Error> {
    Ok(HttpResponse::Ok().into())
}

#[ntex::test]
async fn test_example() {
    let mut srv = test::server(
        || App::new().service(
                web::resource("/").to(my_handler))
    );

    let req = srv.get("/");
    let response = req.send().await.unwrap();
    assert!(response.status().is_success());
}