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
.
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 ()
impl TestHarness for ()
The Unit type can be used as the empty test-harness - it does no initialization and no termination.