Do you need to test the same methods as the methods that mocked Mockito?

I often see the same methods being checked as methods mocked at Mockito(example below). Is there any additional help to call Mockito.verify()in these cases?

//mock method
FooService fs = mock(FooService.class);
when(fs.getFoo()).thenReturn("foo");

//method under test
fs.doSomething();

//verify method
verify(fs).getFoo();

The method does not work if fs.getFoo()not called. So why call verify? I see an advantage if you need to use ArgumentCaptorin validation to validate parameters; except for the case of ArgumentCaptor, is that just superfluous?

+4
source share
2 answers

Mockito , . verify(T) Javadoc Mockito main class Javadoc section 2:

, . , get(0), - ( verify()). , get(0), . ? . .

, " " Mockito Szczepan Faber Mockito. :

? , . . , :

, , , , , ( ), , .

: .

, , ? stub() verify()? ? , . : , , . , , . . , , , , , , n . , -, . , ...

, Mockito , , , . ( " RPC " " LoginCallback " ), , , : , getFoo , , getFoo, "foo", , "foo".


, Mockito, , . - , , ArgumentCaptors, , , - .

+6

, ( , , ), , .

, , ( when), . , .

, , , (, , ), ( , ArgumentCaptor). , , , (, when(fs.getFoo("generatedKey1234")).thenReturn("foo1234")), () verify - .

0

Source: https://habr.com/ru/post/1627724/


All Articles