In what scenarios would using spies be preferable over mocks and stubs?

  • When you need to assert on method invocations
  • When you need to control the return value of a function
  • When you want to isolate the code under test
  • When you want to use real implementations
Using spies is preferable over mocks and stubs when you need to assert on method invocations, as spies can record and report on method calls without altering the original method behavior. Mocks and stubs are more focused on controlling method behavior. Options 2, 3, and 4 are not typical scenarios for using spies.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *