【发布时间】:2021-09-21 08:18:46
【问题描述】:
我可以模拟调用 std::thread 函数的函数吗?
例如 创建线程:
std::thread thread_id
void myfun()
{
thread_id = std::thread(&threadfunction, this);
logger_.Info(LOG001, "Myfun() is called");
}
在另一个函数中加入线程
void final()
{
if (thread_id.joinable())
thread_id.join();
}
在测试部分:
TEST_F(mytest, myfun)
{
EXPECT_CALL(logger_mock_, Info(LOG001, ::testing::_)); //logging expect call
my_class_.myfun(); //my_class_ is instance object.
}
我想测试这个函数,但我收到错误“在没有活动异常的情况下终止调用”。 这意味着线程被创建并超出范围并且测试被终止。 :(
gmock 中可以使用 std::thread 吗?
我还从以下文档中了解到 pthread 用于多线程 Google 测试:
请帮忙。
【问题讨论】:
标签: c++ multithreading stdthread gmock