Attribute Macro tokio::test

source ·
#[test]
Available on crate features rt and macros only.
Expand description

Marks async function to be executed by runtime, suitable to test environment

Usage

Multi-thread runtime

#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
async fn my_test() {
    assert!(true);
}

Using default

The default test runtime is single-threaded.

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

Configure the runtime to start with time paused

#[tokio::test(start_paused = true)]
async fn my_test() {
    assert!(true);
}

Note that start_paused requires the test-util feature to be enabled.

Rename package

use tokio as tokio1;

#[tokio1::test(crate = "tokio1")]
async fn my_test() {
    println!("Hello world");
}