Google Mock: why NiceMock does not ignore unexpected calls?

北城以北 提交于 2019-12-05 12:27:33

Distinctions between NiceMock and StrictMock only come into play if there are no expectations set on the method. But you you have told Google Mock to expect a single call to command with the argument "QUIT". When it sees the second call, it complains.

Maybe you meant this:

EXPECT_CALL(testMock, command("STAT")).Times(1).WillOnce(Return("+OK 1 2\r\n"));
EXPECT_CALL(testMock, command("QUIT"));

which will expect two calls - one with "STAT" as a parameter, and one with "QUIT". Or this:

EXPECT_CALL(testMock, command(_));
EXPECT_CALL(testMock, command("STAT")).Times(1).WillOnce(Return("+OK 1 2\r\n"));

which will expect a single one with the parameter "STAT" and one other call with a parameter other than "STAT". The order of expectations in this case is important as EXPECT_CALL(testMock, command(_)) will satisfy any calls, including the one with "STAT" if it comes after the other expectation.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!