In the context of testing, what is the main difference between a mock and a stub?

  • Stubs are used for functions, while mocks are used for objects
  • Mocks record and verify interactions, while stubs only simulate behavior
  • Stubs are only used in integration tests, while mocks are used in unit tests
  • Mocks are less flexible than stubs
The primary difference between a mock and a stub is that mocks record and verify interactions between the code under test and the dependencies, whereas stubs only simulate the behavior of dependencies. Mocks are used to ensure that specific interactions occur as expected, while stubs focus on controlling the response of functions or methods.
Add your answer
Loading...

Leave a comment

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