Struct actix_web::test::TestServer
source · pub struct TestServer { /* private fields */ }
Expand description
The TestServer
type.
TestServer
is very simple test server that simplify process of writing
integration tests cases for actix web applications.
Examples
use actix_web::test::TestServer;
let mut srv = TestServer::new(|app| app.handler(my_handler));
let req = srv.get().finish().unwrap();
let response = srv.execute(req.send()).unwrap();
assert!(response.status().is_success());
Implementations
sourceimpl TestServer
impl TestServer
sourcepub fn new<F>(config: F) -> Selfwhere
F: Clone + Send + 'static + Fn(&mut TestApp<()>),
pub fn new<F>(config: F) -> Selfwhere
F: Clone + Send + 'static + Fn(&mut TestApp<()>),
Start new test server
This method accepts configuration method. You can add middlewares or set handlers for test application.
sourcepub fn build() -> TestServerBuilder<(), impl Fn() + Clone + Send + 'static>
pub fn build() -> TestServerBuilder<(), impl Fn() + Clone + Send + 'static>
Create test server builder
sourcepub fn build_with_state<S, F>(state: F) -> TestServerBuilder<S, F>where
F: Fn() -> S + Clone + Send + 'static,
S: 'static,
pub fn build_with_state<S, F>(state: F) -> TestServerBuilder<S, F>where
F: Fn() -> S + Clone + Send + 'static,
S: 'static,
Create test server builder with specific state factory
This method can be used for constructing application state. Also it can be used for external dependency initialization, like creating sync actors for diesel integration.
sourcepub fn with_factory<F, H>(factory: F) -> Selfwhere
F: Fn() -> H + Send + Clone + 'static,
H: IntoHttpHandler + 'static,
pub fn with_factory<F, H>(factory: F) -> Selfwhere
F: Fn() -> H + Send + Clone + 'static,
H: IntoHttpHandler + 'static,
Start new test server with application factory
sourcepub fn unused_addr() -> SocketAddr
pub fn unused_addr() -> SocketAddr
Get firat available unused address
sourcepub fn addr(&self) -> SocketAddr
pub fn addr(&self) -> SocketAddr
Construct test server url
sourcepub fn execute<F, I, E>(&mut self, fut: F) -> Result<I, E>where
F: Future<Item = I, Error = E>,
pub fn execute<F, I, E>(&mut self, fut: F) -> Result<I, E>where
F: Future<Item = I, Error = E>,
Execute future on current core
sourcepub fn ws_at(
&mut self,
path: &str
) -> Result<(ClientReader, ClientWriter), ClientError>
pub fn ws_at(
&mut self,
path: &str
) -> Result<(ClientReader, ClientWriter), ClientError>
Connect to websocket server at a given path
sourcepub fn ws(&mut self) -> Result<(ClientReader, ClientWriter), ClientError>
pub fn ws(&mut self) -> Result<(ClientReader, ClientWriter), ClientError>
Connect to a websocket server
sourcepub fn get(&self) -> ClientRequestBuilder
pub fn get(&self) -> ClientRequestBuilder
Create GET
request
sourcepub fn post(&self) -> ClientRequestBuilder
pub fn post(&self) -> ClientRequestBuilder
Create POST
request
sourcepub fn head(&self) -> ClientRequestBuilder
pub fn head(&self) -> ClientRequestBuilder
Create HEAD
request
sourcepub fn client(&self, meth: Method, path: &str) -> ClientRequestBuilder
pub fn client(&self, meth: Method, path: &str) -> ClientRequestBuilder
Connect to test http server