我有EXPECT_CALL(MockObj, func("abc")).Times(1)
和MockObj
是NiceMock
谷歌模擬 - EXPECT_CALL觸發,即使功能有不同的觀點
在我的功能測試,有一個叫MockObj.func("def")
除了MockObj.func("abc")
。
我會想到的是,合理的事情是谷歌模擬說
oh look we call
func("def")
but the arguments do not match theEXPECT_CALL
; nothing to see here
取而代之的是「抱怨」:
unknown file: Failure
Unexpected mock function call - taking default action specified at:
C:/work/unit_test.cpp:36:
Function call: func(84bf3d9 pointing to "def") Returns: 1
Google Mock tried the following 1 expectation, but it didn't match:
unit_test.cpp:50: EXPECT_CALL(MockObj, func("abc"))...
Expected arg #0: is equal to 84c8b96 pointing to "abc"
Actual: 84bf479 pointing to "def"
Expected: to be called once
Actual: called once - saturated and active
首先注意的期望仍然滿意,因爲MockObj.func("abc")
被稱爲
我明白爲什麼GMock拋出了這個錯誤:我宣佈對func
的期望,所以它試圖匹配cal l至func
達到預期但與參數不匹配錯誤
很好。
但爲什麼GMock拋出錯誤?由於參數不匹配,爲什麼這種行爲選擇即
throw an error if the function matches existing
EXPECT_CALL
but not the arguments