Recall when to use stubs, fakes, spies, and mocks without over-coupling the test.
State vs interaction When is a mock stronger than a stub? Mocks verify interactions; stubs supply data. Over-mocking Mock every dependency so the unit is isolated. Use when a test is full of call expectations that do not express the behavior. Your line Isolation matters, but every expectation becomes a design constraint. If state proves the behavior, use a simpler double. Over-mocking can make refactors fail even when behavior is unchanged. It preserves the isolation goal while challenging unnecessary coupling. Fake What makes a fake different from a stub? A working substitute with a shortcut implementation that is useful in…
Sign up free — one personalized lesson every day, matched to your role and goals.
Already have an account? Sign in