Is it possible to run #[tokio::test] marked unit tests via Visual Studio code?

Viewed 666

Is it possible to run #[tokio::test] marked unit tests via Visual Studio code? I don't see the "run test" option for such tests cases.

1 Answers

Update: The current version of the VSCode plugin supports running test marked via #[tokio::test] so this workaround should no longer be necessary.


I have the exact same issue and solved it by using #[tokio::main] and #[test] instead of #[tokio::test]:

async fn answer() -> usize {
    42
}

#[tokio::main]
#[test]
async fn test_answer() {
    assert_eq!(answer().await, 42);
}

When writing async unit tests this way Visual Studio Code is able to run those tests:

Screenshot of VSCode

Related