Skip to main content

server

Function server 

Source
pub fn server<F, S, I>(factory: F) -> TestServer
where F: AsyncFn(&()) -> I + Send + Clone + 'static, S: Service<(), Io> + 'static, I: IntoService<S, (), 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::{self, Method, Response};

#[ntex::test]
async fn test_example() {
    let srv = http::test::server(async |_| {
        http::HttpService::h1(async |_| Ok::<_, std::io::Error>(Response::Ok().build()))
    });

    let req = srv.request(Method::GET, "/");
    let response = req.send().await.unwrap();
    assert!(response.status().is_success());
}