visual-studio-code - 是否可以通过 Visual Studio 代码运行 #[tokio::test] 标记的单元测试?

标签 visual-studio-code rust

是否可以通过 Visual Studio 代码运行 #[tokio::test] 标记的单元测试?我没有看到此类测试用例的“运行测试”选项。

最佳答案

更新 : 当前版本的 VSCode 插件支持通过 #[tokio::test] 标记的运行测试所以这个解决方法不再是必要的。

我有完全相同的问题并通过使用 #[tokio::main] 解决了它和 #[test]而不是 #[tokio::test] :

async fn answer() -> usize {
    42
}

#[tokio::main]
#[test]
async fn test_answer() {
    assert_eq!(answer().await, 42);
}
以这种方式编写异步单元测试时,Visual Studio Code 能够运行这些测试:
Screenshot of VSCode

关于visual-studio-code - 是否可以通过 Visual Studio 代码运行 #[tokio::test] 标记的单元测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60482983/

相关文章:

regex - Visual Studio Code 查找/替换 - 使用名称保存

rust - 要求在继承特征的关联类型上绑定(bind)特征

visual-studio-code - 如果省略 index.js,则转到 ES6 导入的定义

php - 如何在 VS Code 中将 PHP 代码花括号自动格式化为新行

generics - 为什么 `&(?Sized + Trait)`无法转换为 `&dyn Trait`?

generics - 如何在不使函数泛型的情况下将具有泛型的闭包传递给函数?

rust - 如何访问线程本地 LocalKey 静态变量?

rust - 这个理解对吗: trait and function overloading both achieved ad hoc polymorphism but in different direction

node.js - 如何使用 'require' 而不是 'import' 语句

javascript - JavaScript 代码中的运算符 === 更改为三横线