When not to mock
On This Lesson 4 topics
This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.
In this lesson
recognize over-mocking and choose better options.
Planned topics
- Do not mock types you do not own (JDBC,
HttpClient); wrap them in your own interface and mock or fake that. - Do not mock value objects, simple data classes, or collections; use real ones.
- A mock that returns another mock signals bad design or a leaky test.
- Verifying every call ties the test to the implementation.
- Prefer a fake repository for logic tests; prove the real database in integration tests.
Draft outline details
Demonstration
a "before" test with eight mocks and twelve verify lines, and an "after" using a fake repository, one mocked gateway, and result assertions.
Check your understanding
Why avoid mocking a JDBC Connection?
Show answer
You do not own that type; the test would mirror its internals, not behavior.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.