It is good practise to match mock objects widely but verify them precisely. for example: //use below when(myMock.has(any())).thenReturn(myValue); //rather than below when(myMock.has(eq("blah")).thenReturn(myValue);
var result = myMethod();
assertThat(result, is(myValue));
because it is making sure that it is always returned myValue
regardless of the has
method input.
There was a good explanation for this rule but I can not find it. something along the lines: match widely and verify precisely
. would be great if you can advise me about the name of the rule or some reference to it?
Aucun commentaire:
Enregistrer un commentaire