Expecting googlemock calls from another thread

后端 未结 5 597
挽巷
挽巷 2021-01-11 11:26

What will be the best way to write (google) test cases using a google mock object and expect the EXPECT_CALL() definitions being called from another thread controlled by the

5条回答
  •  日久生厌
    2021-01-11 12:21

    So I liked these solutions, but thought it might be easier with a promise, I had to wait for my test to startup:

    std::promise started;
    EXPECT_CALL(mock, start_test())
        .Times(1)
        .WillOnce(testing::Invoke([&started]() {
            started.set_value();
        }));
    system_->start();
    EXPECT_EQ(std::future_status::ready, started.get_future().wait_for(std::chrono::seconds(3)));
    

提交回复
热议问题