Function ntex::web::test::init_service

source ยท
pub async fn init_service<R, S, E>(
    app: R
) -> Pipeline<impl Service<Request, Response = WebResponse, Error = E>>
Expand description

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);
}