[][src]Function actix_web::test::init_service

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

This method accepts application builder instance, and constructs service.

use actix_service::Service;
use actix_web::{test, web, App, HttpResponse, http::StatusCode};

#[actix_rt::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);
}