Java Test Doubles

Choosing and using test doubles in Java: the stub/mock/fake distinction that actually changes what a test proves, preferring the real collaborator or a hand-written fake over a mock, verifying interactions only when the interaction is the outcome, Mockito's strict stubs, and the rule against mocking types you do not own. Use when a test mocks every collaborator the class touches, when verify is asserted on a query, when a refactoring broke tests that still describe correct behaviour, when deep stubs or static mocking are proposed, when a stubbed repository is hiding a query that does not work, when UnnecessaryStubbingException appears, or when migrating from @MockBean. Does not cover which level to test at (java-testing-strategy), how the test is written (java-test-design), deterministic executors for threading (concurrency-testing), or breaking a dependency so the class can be constructed at all (java-legacy-code-testing).

robsonkades 75e5743 4 files · 21.3 KB Updated

File contents

robsonkades/agent-skills/tree/main/skills/java-test-doubles commit 75e5743f00

Frequently asked questions

npx skillmds@latest add robsonkades/java-test-doubles