A macro test helper to help you to write integration tests.
Basically:
fn setup()
before your testfn teardown()
after the test endAdd the following to your Cargo.toml
[dependencies]
tearup = "0.1"
Your test will look like this:
```rust
async fn isshoulddothat(mut db: DbConnection) { // assert something using somethingyouneedin_test }
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
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)
pub struct SomethingYouSetup;
impl FromAsyncContext<', YourContext> for SomethingYouSetup { async fn fromsetup(context: &YourContext) -> Self { context.somethingyouneedintest.clone() } }
// And write your tests !
async fn isshoulddothat(mut somethingyouneedintest: SomethingYouSetup) { // assert something using somethingyouneedin_test } ```