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

pub async fn init_service<R, S, E>(
    app: R
) -> impl Service<Request = Request, Response = WebResponse, Error = E> where
    R: IntoServiceFactory<S>,
    S: ServiceFactory<Config = AppConfig, Request = Request, Response = WebResponse, Error = E>,
    S::InitError: Debug

This method accepts application builder instance, and constructs service.

use ntex::service::Service;
use ntex::http::StatusCode;
use ntex::web::{self, test, App, HttpResponse};

#[ntex::test]
async fn test_init_service() {
    let mut app = test::init_service(
        App::new()
            .service(web::resource("/test").to(|| async { HttpResponse::Ok() }))
    ).await;

    // Create request object
    let req = test::TestRequest::with_uri("/test").to_request();

    // Execute application
    let resp = app.call(req).await.unwrap();
    assert_eq!(resp.status(), StatusCode::OK);
}