googletest icon indicating copy to clipboard operation
googletest copied to clipboard

Exception inside ON_CALL will not be catched

Open RocketFan opened this issue 2 years ago • 1 comments

Hi,

When I use ON_CALL with WillByDefault and try to throw exception inside it, that will not be catched by EXPECT_THROW. Also I am getting an error which says that exception was thrown during tests.

For example:

MockClass

class MockClass : public SomeClass
{
public:
     MOCK_METHOD(void, someFunction, (), (override);
}

MockClassTests

TEST
{
     MockClass mock;

     ON_CALL(mock, someFunction).WillByDefault([]() {
           throw std::runtime_error{"error message"};
     });

     EXPECT_THROW(mock.someFunction(), std::runtime_error);
}

RocketFan avatar Aug 08 '22 11:08 RocketFan