Function actix_test::start_with
source · pub fn start_with<F, I, S, B>(cfg: TestServerConfig, factory: F) -> TestServerwhere
F: Fn() -> I + Send + Clone + 'static,
I: IntoServiceFactory<S, Request>,
S: ServiceFactory<Request, Config = AppConfig> + 'static,
S::Error: Into<Error> + 'static,
S::InitError: Debug,
S::Response: Into<Response<B>> + 'static,
<S::Service as Service<Request>>::Future: 'static,
B: MessageBody + 'static,
Expand description
Start test server with custom configuration
Check TestServerConfig
docs for configuration options.
§Examples
use actix_web::{get, web, test, App, HttpResponse, Error, Responder};
#[get("/")]
async fn my_handler() -> Result<impl Responder, Error> {
Ok(HttpResponse::Ok())
}
#[actix_web::test]
async fn test_example() {
let srv = actix_test::start_with(actix_test::config().h1(), ||
App::new().service(my_handler)
);
let req = srv.get("/");
let res = req.send().await.unwrap();
assert!(res.status().is_success());
}