Although this question was already answered, still I'm not clear which one should I use during mocking
While referring to spock.lang.MockingApi.java
. I couldn't able to catch any difference between any of these.
The documentation for Mock
is saying
Person person = Mock() // type is Person.class, name is "person"
The documentation for Spy
is saying
Person person = Spy() // type is Person.class, name is "person"
The documentation for Stub
is saying
Person person = Stub() // type is Person.class, name is "person"
which is clearly stating that there is no difference between any of these. So why we having these three mocking strategy in place and what exactly the difference between then and when to use them.
It would be much helpful, if it is an answer with sample code.