tearup

A macro test helper to help you to write integration tests.

Basically:

Install

Add the following to your Cargo.toml

[dependencies]
tearup = "0.1"

Usage

Your test will look like this:

```rust

[tearup_test(DbContext)]

async fn isshoulddothat(mut db: DbConnection) { // assert something using somethingyouneedin_test }

[tearup_test(AnotherContext)]

fn isshoulddothat(address: Address) { // assert something using somethingyouneedin_test } ```

How to implements:

```rust use asynctrait::asynctrait; use tearup::{tearup_test, AsyncContext, FromAsyncContext, ReadyFn};

// First define your context struct YourContext { somethingyouneedintest: SomethingYouSetup, }

// Second implement your setup/teardown

[async_trait]

impl<'a> AsyncContext<'a> for YourContext { async fn setup(ready: ReadyFn) -> Self { /* --> do your stuff here <-- */

    ready(); // notify that your setup id ready

    Self { something_you_need_in_test: SomethingYouSetup{} }
}

async fn teardown(&mut self) { /* --> clean your stuff here <-- */ }

}

// Optionnaly define some setup accessor // if you need to access something from your setup (like db connection, seed, etc)

[derive(Clone)]

pub struct SomethingYouSetup;

[async_trait]

impl FromAsyncContext<', YourContext> for SomethingYouSetup { async fn fromsetup(context: &YourContext) -> Self { context.somethingyouneedintest.clone() } }

// And write your tests !

[tearup_test(YourContext)]

async fn isshoulddothat(mut somethingyouneedintest: SomethingYouSetup) { // assert something using somethingyouneedin_test } ```

More examples here