Trait test_harness::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§
Required Methods§
sourcefn init(
shared_state: &Arc<SharedState>
) -> BoxFuture<'static, Result<(Self, Self::Env, Self::Runner), Error>>
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
.
Implementations on Foreign Types§
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)
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 + 'static, Global>>
fn init( shared_state: &Arc<SharedState> ) -> BoxFuture<'static, Result<(Self, Self::Env, Self::Runner), Error>>
fn terminate(environment: Self::Env) -> BoxFuture<'static, Result<(), Error>>
source§impl TestHarness for ()
impl TestHarness for ()
The Unit type can be used as the empty test-harness - it does no initialization and no termination.