adtest

Crates.ioadtest
lib.rsadtest
version0.1.0
sourcesrc
created_at2023-10-09 16:04:27.763188
updated_at2023-10-09 16:04:27.763188
descriptionLibrary for better test generation
homepage
repositoryhttps://github.com/0xMimir/adtest
max_upload_size
id998209
size14,793
(0xMimir)

documentation

README

ADTEST

codecov

This crate allows you to easily create tests with setup and cleanup functions, like beforeEach and afterEach functions in jest, it offers this functionality for both async and non-async test.

To use simply add to your crate in lib.rs or main.rs

#[macro_use] extern crate adtest;

After that add #[adtest] to desired function

#[adtest]
fn complex_test(){
    println!("I like to test things");
}

If used solely it behaves as #[test] on non async function and on async functions as #[tokio::test]. But unlike those, #[adtest] allows you to add setup and clean up functions to run before/after your tests.

Example of test with setup

#[adtest(setup = setup_function)]
fn complex_test(){
    println!("I like to test things");
}

fn setup_function(){
    println!("I will do some setup things");
}

If your setup/cleanup function is async you must specify it with async keyword before test name:

#[adtest(
    setup = setup_function,
    cleanup = async cleanup_function
)]
fn complex_test(){
    println!("I like to test things");
}

fn setup_function(){
    println!("I will do some setup things");
}

async fn cleanup_function(){
    println!("I am async function")
}
Commit count: 11

cargo fmt