pub trait TestHarness: Sized {
    type Env: Send + 'static;
    type Runner: Future<Output = Result<(), Error>> + Unpin + Send + 'static;

    // Required methods
    fn init(
        shared_state: &Arc<SharedState>
    ) -> BoxFuture<'static, Result<(Self, Self::Env, Self::Runner), Error>>;
    fn terminate(env: Self::Env) -> BoxFuture<'static, Result<(), Error>>;
}
Expand description

A TestHarness is a type that provides an interface to test cases for interacting with functionality under test. For example, a WidgetHarness might provide controls for interacting with and measuring a Widget, allowing us to easily write tests for Widget functionality.

A TestHarness defines how to initialize (via init()) the harness resources and how to terminate (via terminate()) them when done. The init() function can also provide some environment resources (env) to be held for the test duration, and also a task (runner) that can be executed to perform asynchronous behavior necessary for the test harness to function correctly.

Required Associated Types§

source

type Env: Send + 'static

The type of environment needed to be held whilst the test runs. This is normally used to keep resources open during the test, and allow a graceful shutdown in terminate.

source

type Runner: Future<Output = Result<(), Error>> + Unpin + Send + 'static

A future that models any background computation the harness needs to process. If no processing is needed, implementations should use future::Pending to model a future that never returns Poll::Ready

Required Methods§

source

fn init( shared_state: &Arc<SharedState> ) -> BoxFuture<'static, Result<(Self, Self::Env, Self::Runner), Error>>

Initialize a TestHarness, creating the harness itself, any hidden environment, and a runner task to execute background behavior. May index into shared_state to access state that needs to be shared across Harnesses. If init needs to access shared_state inside the returned future, it should clone the state outside of the future and move it into the future.

shared_state will be dropped before the test code executes, so if a shared state entry must exist for the duration of the test, Harnesses should add it to their Env.

source

fn terminate(env: Self::Env) -> BoxFuture<'static, Result<(), Error>>

Terminate the TestHarness. This should clear up any and all resources that were created by init()

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl TestHarness for ()

The Unit type can be used as the empty test-harness - it does no initialization and no termination.

§

type Env = ()

§

type Runner = Pending<Result<(), Error>>

source§

fn init( _shared_state: &Arc<SharedState> ) -> BoxFuture<'static, Result<(Self, Self::Env, Self::Runner), Error>>

source§

fn terminate(_env: Self::Env) -> BoxFuture<'static, Result<(), Error>>

source§

impl<A: TestHarness + Send, B: TestHarness + Send> TestHarness for (A, B)

§

type Env = (<A as TestHarness>::Env, <B as TestHarness>::Env)

§

type Runner = Pin<Box<dyn Future<Output = Result<(), Error>> + Send>>

source§

fn init( shared_state: &Arc<SharedState> ) -> BoxFuture<'static, Result<(Self, Self::Env, Self::Runner), Error>>

source§

fn terminate(environment: Self::Env) -> BoxFuture<'static, Result<(), Error>>

source§

impl<A: TestHarness + Send, B: TestHarness + Send, C: TestHarness + Send> TestHarness for (A, B, C)

§

type Env = (<A as TestHarness>::Env, <B as TestHarness>::Env, <C as TestHarness>::Env)

§

type Runner = Pin<Box<dyn Future<Output = Result<(), Error>> + Send>>

source§

fn init( shared_state: &Arc<SharedState> ) -> BoxFuture<'static, Result<(Self, Self::Env, Self::Runner), Error>>

source§

fn terminate(environment: Self::Env) -> BoxFuture<'static, Result<(), Error>>

source§

impl<A: TestHarness + Send, B: TestHarness + Send, C: TestHarness + Send, D: TestHarness + Send> TestHarness for (A, B, C, D)

§

type Env = (<A as TestHarness>::Env, <B as TestHarness>::Env, <C as TestHarness>::Env, <D as TestHarness>::Env)

§

type Runner = Pin<Box<dyn Future<Output = Result<(), Error>> + Send>>

source§

fn init( shared_state: &Arc<SharedState> ) -> BoxFuture<'static, Result<(Self, Self::Env, Self::Runner), Error>>

source§

fn terminate(environment: Self::Env) -> BoxFuture<'static, Result<(), Error>>

source§

impl<A: TestHarness + Send, B: TestHarness + Send, C: TestHarness + Send, D: TestHarness + Send, E: TestHarness + Send> TestHarness for (A, B, C, D, E)

§

type Env = (<A as TestHarness>::Env, <B as TestHarness>::Env, <C as TestHarness>::Env, <D as TestHarness>::Env, <E as TestHarness>::Env)

§

type Runner = Pin<Box<dyn Future<Output = Result<(), Error>> + Send>>

source§

fn init( shared_state: &Arc<SharedState> ) -> BoxFuture<'static, Result<(Self, Self::Env, Self::Runner), Error>>

source§

fn terminate(environment: Self::Env) -> BoxFuture<'static, Result<(), Error>>

source§

impl<A: TestHarness + Send, B: TestHarness + Send, C: TestHarness + Send, D: TestHarness + Send, E: TestHarness + Send, F: TestHarness + Send> TestHarness for (A, B, C, D, E, F)

§

type Env = (<A as TestHarness>::Env, <B as TestHarness>::Env, <C as TestHarness>::Env, <D as TestHarness>::Env, <E as TestHarness>::Env, <F as TestHarness>::Env)

§

type Runner = Pin<Box<dyn Future<Output = Result<(), Error>> + Send>>

source§

fn init( shared_state: &Arc<SharedState> ) -> BoxFuture<'static, Result<(Self, Self::Env, Self::Runner), Error>>

source§

fn terminate(environment: Self::Env) -> BoxFuture<'static, Result<(), Error>>

Implementors§