tearup

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

Basically:

Install

Add the following to your Cargo.toml

yaml [dependencies] tearup = "0.1"

Usage

Your test will look like this:

```rust

[tearup_test(DbContext)]

async fn itshoulddo_that(mut db: DbConnection) { // assert something }

[tearup_test(WebContext)]

fn itshoulddo_this(address: Address) { // assert something }

type BothContext = ConcurrentContextCombinator;

[tearup_test(BothContext)]

fn itshoulddo_this(mut db: DbConnection, address: Address) { // assert something } ```

  1. Choose your context (async versions exist too):
  2. Implement it, here the simple async implementation:

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

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

// Second implement your setup/teardown

[async_trait]

impl<'a> AsyncSimpleContext<'a> for YourContext { async fn setup() -> Self { /* --> do your stuff here <-- */ Self { somethingyouneedintest: 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 fromcontext(context: &YourContext) -> Self { context.somethingyouneedintest.clone() } }

// And write your tests !

[tearup_test(YourContext)]

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

  1. Combine your contexts with (async versions exist too):

```rust type BothContext = ConcurrentContextCombinator;

[tearup_test(BothContext)]

fn itshoulddothis(mut somethingyouneedintest: DbConnection, somethingfromtheother_context: Address) { // assert something } ```

More examples here