je EXPECT_CALL(MockObj, func("abc")).Times(1)
et MockObj
est un NiceMock
google simulation - EXPECT_CALL déclenche même si la fonction a argument différent
Dans ma fonction en cours de test, il y a un appel MockObj.func("def")
en plus deMockObj.func("abc")
.
Je pense que la chose raisonnable à faire est pour Google Mock dire
oh look we call
func("def")
but the arguments do not match theEXPECT_CALL
; nothing to see here
Mais au lieu de cela « se plaint »:
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
premier avis que l'attente était toujours satisfaite parce que MockObj.func("abc")
a été appelé
Je comprends pourquoi GMock a jeté l'erreur: J'ai déclaré une attente sur func
alors il a essayé de faire correspondre le cal l à func
à l'attente, mais il ne correspond pas aux arguments donc erreur
Fine.
Mais pourquoi GMock lance-t-il une erreur ? Étant donné que les arguments ne correspondent pas, pourquoi ce comportement choisi à savoir
throw an error if the function matches existing
EXPECT_CALL
but not the arguments