test_harness

Trait TestHarness

Source
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()

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so 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.

Source§

type Env = ()

Source§

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)

Source§

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

Source§

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)

Source§

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

Source§

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)

Source§

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

Source§

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)

Source§

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

Source§

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)

Source§

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)

Source§

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§