Skip to main content

server

Function server 

Source
pub fn server<F, I, Sf>(factory: F) -> TestServer
where F: AsyncFn(&()) -> I + Send + Clone + 'static, I: IntoServiceFactory<Sf, (), Request>, Sf: ServiceFactory<(), Request> + 'static, Sf::Res: Into<Response>, Sf::Error: ResponseError, Sf::InitError: Debug,
Expand description

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 srv = test::server(
        async |_| App::new().service(
                web::resource("/").to(my_handler))
    );

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