Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Current »

According to the API docks - both can be used to mock methods or fields. The difference is that with a mock, you are creating a complete mock or fake object whilst with a spy, there is the real object and you just spying or stubbing out specific methods.

When using mock objects (e.g. @Mock), the default behaviour of the method when not stub is do nothing. Meaning, if its a void method, then it will do nothing when you call the method or if its a method with a non void return type then it may return null, empty or the default value.

When working as a spy, then a whole object actually does exist, Because the object is real, the method is real if do not stub out the method, Mockito will then call the real method. If you want to Spy on or change the method, then you should stub it out.

  • No labels

0 Comments

You are not logged in. Any changes you make will be marked as anonymous. You may want to Log In if you already have an account.