advanced~3h
Testing Interview Deep Dive
A capstone walk through the testing questions that actually separate candidates in an interview — why a test can pass locally and fail in CI, the real mechanical difference between @Mock and @MockBean, how to test code that depends on Thread.sleep or the current time, why @DataJpaTest sometimes sees stale data, and how to approach a flaky integration test — each explained through real reasoning and code, not as a flashcard list.
Learning objectives
- Diagnose why a test suite passes locally but fails in CI by reasoning about environment and ordering differences
- Explain precisely why @Mock and @MockBean are not interchangeable, down to the ApplicationContext
- Test time-dependent and sleep-dependent code deterministically using a Clock abstraction and Awaitility
- Explain why a @DataJpaTest can observe stale data and how transaction and cache boundaries cause it
- Approach a genuinely flaky integration test systematically rather than by adding retries or sleeps
This is a Pro chapter
Sign in, then upgrade to Pro or Power to unlock this and the full Core Java Mastery library.
Testing Interview Deep Dive