intermediateTesting427 of 436

Difference between @Mock and @Spy in JUnit.

Tests whether you know @Mock creates a fully fake object with no real behavior unless stubbed, while @Spy wraps a real object so unstubbed methods execute their actual implementation -- useful when you want to verify interactions on mostly-real behavior.

Ready to master this question?

Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.

Sign in to generate a response

Next Step

← Back to all Core Java questions