Skip to main content

AsyncTestResource

Trait AsyncTestResource 

Source
pub trait AsyncTestResource: Sized + Send {
    // Required methods
    fn setup<'async_trait>(    ) -> Pin<Box<dyn Future<Output = Self> + Send + 'async_trait>>
       where Self: 'async_trait;
    fn teardown<'async_trait>(
        self,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait;
}
Expand description

Async version of TestResource for async setup/teardown

Implement this trait for test resources that require asynchronous initialization or cleanup.

§Examples

use reinhardt_testkit::resource::AsyncTestResource;

struct AsyncTestEnv {
    connection: String,
}

#[async_trait::async_trait]
impl AsyncTestResource for AsyncTestEnv {
    async fn setup() -> Self {
        // Async initialization
        Self { connection: "test_db".to_string() }
    }

    async fn teardown(self) {
        // Async cleanup
    }
}

Required Methods§

Source

fn setup<'async_trait>() -> Pin<Box<dyn Future<Output = Self> + Send + 'async_trait>>
where Self: 'async_trait,

Async setup hook called before each test

Source

fn teardown<'async_trait>( self, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,

Async teardown hook called after each test

Takes ownership of self to ensure cleanup.

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.

Implementors§