In unit testing, stubs, mocks, and spies are test doubles used to isolate the unit of code being tested from its dependencies. They each serve distinct purposes: 1. Stubs: A stub provides canned answers to calls made during the test. They are used to replace dependencies with controlled inputs, allowing you to test different scenarios in your unit of code. Stubs are primarily concerned with *state verification*, ensuring that the unit under test behaves correctly based on different input states. Example: Imagine you are testing a function that retrieves a user's profile from a database. You can use a stub to replace the database access layer. The stub will return a predefined user profile, allowing you to test how the function handles different profile scenarios (e.g., a user with a premium account vs. a user with a basic acc....
Log in to view the answer