Skip to main content

TestResource

Trait TestResource 

Source
pub trait TestResource: Sized {
    // Required methods
    fn setup() -> Self;
    fn teardown(&mut self);
}
Expand description

Per-test resource with setup and teardown hooks

Implement this trait to define test resources that need initialization before each test and cleanup after each test.

§Examples

use reinhardt_testkit::resource::TestResource;

struct TestEnv {
    data: Vec<String>,
}

impl TestResource for TestEnv {
    fn setup() -> Self {
        Self { data: vec![] }
    }

    fn teardown(&mut self) {
        self.data.clear();
    }
}

Required Methods§

Source

fn setup() -> Self

Setup hook called before each test (BeforeEach)

Source

fn teardown(&mut self)

Teardown hook called after each test (AfterEach)

This is called automatically by TeardownGuard::drop, ensuring cleanup even if the test panics.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§