有一個帶有一個字串引數的方法 virtual void method(const std::string& str) = 0;
在某些情況下,我需要確保沒有使用特定引數呼叫此方法,例如“321”。
如果該方法在某處被呼叫,ifce->method("123");并且在我所做EXPECT_CALL(mock, method("321")).Times(0);的測驗中,則測驗失敗:
Expected arg #0: is equal to "321"
Actual: "123"
Expected: to be never called
Actual: never called - saturated and active
[ FAILED ] test.invokeMethodWithDiferentParameters (0 ms)
如何正確地做到這一點?
uj5u.com熱心網友回復:
要么使用testing::NiceMock,它會忽略所有無趣的呼叫
NiceMock<MockFoo> mock;
EXPECT_CALL(mock, method("321")).Times(0);
或者加幾個期望
EXPECT_CALL(mock, method(_)).Times(AtLeast(1));
EXPECT_CALL(mock, method("321")).Times(0);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/359942.html
