Skip to main content

test

Attribute Macro test 

Source
#[test]
Expand description

Mark a function as a test. This will add the function to the list of tests in a special global section. The tests can be accessed using test::test_cases or test::collect_tester.

§Example

#[tarantool::test]
fn my_test() {
    assert!(true);
}

#[tarantool::test(should_panic)]
fn my_panicking_test() {
    assert!(false);
}

You can also have tests which should panic only in certain conditions. This is done by specifying a constant expression as an argument to the should_panic keyword. Here’s an example:

#[tarantool::test(should_panic = cfg!(debug_assertions))]
fn only_panics_in_debug_mode() {
    debug_assert!(false);
}

You can also use #[tarantool::test] with async functions, in which case the body of the test will be wrapped inside fiber::block_on(async {}) block. The following two tests are equivalent:

#[tarantool::test]
async fn async_test_1() {
    assert_eq!(foo().await, 1);
}

#[tarantool::test]
fn async_test_2() {
    tarantool::fiber::block_on(async {
        assert_eq!(foo().await, 1);
    })
}

async fn foo() -> i32 {
    1
}

Mark a function as a test.

See tarantool::test doc-comments in tarantool crate for details.