No description
Find a file
Mark Hildreth f07f348c44
Merge pull request #9 from Shadow53/impl-sync-for-async
add basic impl TestContext for AsyncTestContext
2021-02-23 20:39:46 -05:00
.github/workflows Updated github ci.yml 2021-01-17 22:15:43 -05:00
macros Forced futures to be imported through test_context crate. 2021-02-06 23:44:33 -05:00
src run cargo fmt 2021-02-21 17:33:27 -08:00
tests add basic impl TestContext for AsyncTestContext 2021-02-21 17:30:31 -08:00
.gitignore Initial commit 2021-01-17 15:20:15 -05:00
Cargo.toml Bumped to version v0.1.2 2021-02-07 00:13:22 -05:00
LICENSE Initial commit 2021-01-17 15:20:15 -05:00
README.md Added badges 2021-02-07 00:08:29 -05:00
README.tpl Added badges 2021-02-07 00:08:29 -05:00

crates.io Documentation License Github

test-context

A library for providing custom setup/teardown for Rust tests without needing a test harness.

use test_context::{test_context, TestContext};

struct MyContext {
    value: String
}

impl TestContext for MyContext {
    fn setup() -> MyContext {
        MyContext {  value: "Hello, world!".to_string() }
    }

    fn teardown(self) {
        // Perform any teardown you wish.
    }
}

#[test_context(MyContext)]
#[test]
fn test_works(ctx: &mut MyContext) {
    assert_eq!(ctx.value, "Hello, world!");
}

Works with other test wrappers like actix_rt::test or tokio::test that turn your test function into an async function.

use test_context::{test_context, AsyncTestContext};

struct MyAsyncContext {
    value: String
}

#[async_trait::async_trait]
impl AsyncTestContext for MyAsyncContext {
    async fn setup() -> MyAsyncContext {
        MyAsyncContext { value: "Hello, world!".to_string() }
    }

    async fn teardown(self) {
        // Perform any teardown you wish.
    }
}

#[test_context(MyAsyncContext)]
#[tokio::test]
async fn test_works(ctx: &mut MyAsyncContext) {
    assert_eq!(ctx.value, "Hello, World!");
}

License: MIT