Crate trillium_testing[][src]

Expand description

testing utilities for trillium applications.

this crate is intended to be used as a development dependency.

use trillium_testing::prelude::*;
use trillium::{Conn, conn_try};
async fn handler(mut conn: Conn) -> Conn {
    let request_body = conn_try!(conn.request_body_string().await, conn);
    conn.with_body(format!("request body was: {}", request_body))
        .with_header("request-id", "special-request")

    post("/").with_request_body("hello trillium!").on(&handler),
    "request body was: hello trillium!",
    "request-id" => "special-request",
    "content-length" => "33"


You must enable a runtime feature for trillium testing


trillium-testing = { version = "0.2", , features = ["tokio"] }


trillium-testing = { version = "0.2", , features = ["async-std"] }


trillium-testing = { version = "0.2", , features = ["smol"] }


pub use futures_lite;


TestConn builders for http methods

useful stuff for testing trillium apps


assert that the response body is as specified. this assertion requires mutation of the conn.

asserts that the response body matches the specified pattern, using str::contains

asserts any number of response headers

assert that all of the following are true:

assert_ok is like assert_response! except it always asserts a status of 200 Ok.

combines several other assertions. this assertion can be used to assert:

assert that the status code of a conn is as specified.


A wrapper around a trillium::Conn for testing

a readable and writable transport for testing

A parsed URL record.


HTTP request methods.

HTTP response status codes.


Read bytes asynchronously.

Extension trait for AsyncRead.

Write bytes asynchronously.


Runs the global and the local executor on the current thread

initialize a handler

Starts a trillium handler bound to a random available port on localhost, run the async tests provided as the second argument, and then shut down the server. useful for full integration tests that actually exercise the tcp layer.

start a trillium server on a random port for the provided handler, establish a tcp connection, run the provided test function with that tcp stream, and shut down the server.