Skip to main content

Fixture

Trait Fixture 

Source
pub trait Fixture:
    Any
    + Send
    + Sync {
    // Required methods
    fn setup(&mut self) -> ProbarResult<()>;
    fn teardown(&mut self) -> ProbarResult<()>;

    // Provided methods
    fn name(&self) -> &str { ... }
    fn priority(&self) -> i32 { ... }
}
Expand description

Trait for test fixtures that can be set up and torn down.

Implement this trait to create reusable test fixtures that manage setup and cleanup of test resources.

§Example

struct DatabaseFixture {
    connection: Option<DbConnection>,
}

impl Fixture for DatabaseFixture {
    fn setup(&mut self) -> ProbarResult<()> {
        self.connection = Some(DbConnection::connect("test_db")?);
        Ok(())
    }

    fn teardown(&mut self) -> ProbarResult<()> {
        if let Some(conn) = self.connection.take() {
            conn.close()?;
        }
        Ok(())
    }
}

Required Methods§

Source

fn setup(&mut self) -> ProbarResult<()>

Set up the fixture before test execution.

§Errors

Returns an error if fixture setup fails.

Source

fn teardown(&mut self) -> ProbarResult<()>

Tear down the fixture after test execution.

§Errors

Returns an error if fixture teardown fails.

Provided Methods§

Source

fn name(&self) -> &str

Get the fixture name for logging/debugging.

Source

fn priority(&self) -> i32

Get fixture priority (higher = set up first, tear down last).

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§