I'm a bit confused with stubbing syntax.
what is the difference between:
stub(mock.someMethod()).toReturn(10);
and
when(mock.someMethod()).toReturn(10);
According to the stub
method's documentation :
Some users find
stub()
confusing thereforeMockito.when(Object)
is recommended overstub()
.
So basically they are the same . But as the stub
method returns a DeprecatedOngoingStubbing
(note the word deprecated ), the when
method is obviously meant to be used.
As specified in the official Mockito's tutorial :
when()
is a successor of deprecatedstub(Object)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.