c++ - this_thread::sleep_for 在 WSL 的谷歌测试中不起作用

标签 c++ googletest windows-subsystem-for-linux chrono

我正在尝试在 Google 测试中 sleep 。根据this post ,我可以使用以下内容:

#include <chrono>
#include <thread>
TEST_F(TestSuite, TestOne) {
    // f1();
    std::this_thread::sleep_for(std::chrono::seconds(2));
    // f2();
}
我将此命令放在测试中,但它不会改变任何东西。代码执行很快,因为它省略了 sleep 。我正在使用 g++ (Ubuntu 9.3.0-10ubuntu2) 9.3.0。
我可能做错了什么?

最佳答案

你的测试真的执行了吗?我建议将临时 std::cout << "STARTING TEST" << std::endl;在测试开始时检查您是否可以在输出中看到这些单词。

关于c++ - this_thread::sleep_for 在 WSL 的谷歌测试中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63171696/

相关文章:

file - 在 WSL 中运行 shell 脚本时出现 "E: Invalid operation update"错误

c++ - Eigen 3/C++ : Tile a MatrixXd with a Vector3d

c++ - 带有 gtest 框架的 Spdlog 记录器无法工作

c++ - 将 vector<Derived*> 转换为 vector<Base*> 时如何避免复制

c++ - 从 Google 模拟中的模拟对象返回模拟对象

c++ - 谷歌模拟 ByRef 方法

ada - 从适用于 Linux 的 Windows 子系统调用时,GPRBuild 找不到 gprconfig

bash - 如何在 WSL2 中运行的 vscode 中设置 bash

c++ - 从 C 到 Erlang 的高性能消息传递

c++ - 包括标题和 Main.h