What is the difference between a test stub and a mock?
Answer
Both are test doubles but serve different purposes. A stub provides indirect inputs to the system under test — it returns predefined values when called. You don't verify how or whether the stub was called — you only care about the output it provides. Example: stub.GetUser(1) always returns a specific User object regardless of how many times it's called. A mock verifies indirect outputs — it sets expectations on what calls should be made and verifies them at the end of the test. If the expected call doesn't happen (or happens with wrong args), the test fails. Example: mock.Verify(r => r.SaveUser(It.IsAny<User>()), Times.Once);. Stubs answer the question "what data should the dependency return?" Mocks answer the question "was the dependency called correctly?" Over-mocking (verifying every interaction) leads to brittle tests. Prefer stubs when you only care about behavior; use mocks only when the interaction itself (the call) is what you're testing.