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
yaml
[dependencies]
tearup = "0.1"
Your test will look like this:
```rust
async fn itshoulddo_that(mut db: DbConnection) { // assert something }
fn itshoulddo_this(address: Address) { // assert something }
type BothContext = ConcurrentContextCombinator
fn itshoulddo_this(mut db: DbConnection, address: Address) { // assert something } ```
SimpleContext
: for basic setup/teardown actionsWaitingContext
: in case your setup/teardown are asyncronous and you need a polling/notification helper (here an example waiting a rocket server to be up)```rust use asynctrait::asynctrait; use tearup::{tearup_test, AsyncSimpleContext, FromAsyncContext};
// First define your context struct YourContext { somethingyouneedintest: SomethingYouSetup, }
// Second implement your setup/teardown
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)
pub struct SomethingYouSetup;
impl FromAsyncContext<', YourContext> for SomethingYouSetup { async fn fromcontext(context: &YourContext) -> Self { context.somethingyouneedintest.clone() } }
// And write your tests !
async fn itshoulddothat(mut somethingyouneedintest: SomethingYouSetup) { // assert something using somethingyouneedin_test } ```
SequentialContextCombinator
: executing setup/teardown one after the other, usefull when one context require the otherConcurrentContextCombinator
: executing setup/teardown actions in parallel```rust
type BothContext = ConcurrentContextCombinator
fn itshoulddothis(mut somethingyouneedintest: DbConnection, somethingfromtheother_context: Address) { // assert something } ```