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§
Sourcefn setup(&mut self) -> ProbarResult<()>
fn setup(&mut self) -> ProbarResult<()>
Sourcefn teardown(&mut self) -> ProbarResult<()>
fn teardown(&mut self) -> ProbarResult<()>
Provided Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".