Function actix_web::test::start_with [−][src]
pub fn start_with<F, I, S, B>(cfg: TestServerConfig, factory: F) -> TestServer where
F: Fn() -> I + Send + Clone + 'static,
I: IntoServiceFactory<S>,
S: ServiceFactory<Config = AppConfig, Request = Request> + 'static,
S::Error: Into<Error> + 'static,
S::InitError: Debug,
S::Response: Into<HttpResponse<B>> + 'static,
<S::Service as Service>::Future: 'static,
B: MessageBody + 'static,
Expand description
Start test server with custom configuration
Test server could be configured in different ways, for details check
TestServerConfig
docs.
Examples
use actix_web::{web, test, App, HttpResponse, Error};
async fn my_handler() -> Result<HttpResponse, Error> {
Ok(HttpResponse::Ok().into())
}
#[actix_rt::test]
async fn test_example() {
let mut srv = test::start_with(test::config().h1(), ||
App::new().service(web::resource("/").to(my_handler))
);
let req = srv.get("/");
let response = req.send().await.unwrap();
assert!(response.status().is_success());
}