小编lin*_*oob的帖子

C++ returning a future

I'm using google test and am trying to mock a method that returns a future. What I'm doing is creating some future object in a test case, then I do "when(mock.Call()).thenReturn(myFutureObject), but I get an error "use of deleted function std::future<_res>::future(const std::future<_Res>&)".

This is the code:

std::promise<MyClass> pr;
std::future<MyClass> fut { pr.get_future() };

std::cout << fut.valid() << std::endl; // this returns 1 so it seems I have a valid future object

EXPECT_CALL(mockSvc, mymethod()).WillOnce(Return(std::move(fut)));

// this "expected call" throws an error …
Run Code Online (Sandbox Code Playgroud)

c++ unit-testing future mocking promise

5
推荐指数
1
解决办法
1494
查看次数

标签 统计

c++ ×1

future ×1

mocking ×1

promise ×1

unit-testing ×1