roadmap
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
Prepare for MockK interview questions on mocking Kotlin code, from a first every and verify to how calls are intercepted. Covers stubbing, matchers, verification, objects and statics, and coroutines.
205 of 205 questions in your plan: 0 known, 0 in progress, 0 due, 0 skipped, 205 new. 0 cut, outside your plan.
MockK rarely gets a round of its own. It surfaces inside the testing conversation of a Kotlin backend or Android loop, often as a test you are asked to write or repair on the spot: a service with two collaborators, one of them a `suspend` repository, and a bug the test should catch. Interviewers then pull on the details. Why does a call nobody stubbed throw on a plain `mockk<T>()` but quietly return a default on a relaxed one? Why will `any()` not compile outside an `every` or `verify` block, and why does mixing a matcher with a plain literal sometimes break? What string does `mockkStatic` need before it can stub a top-level function? The levels part on how far down the explanation reaches. Getting the stub and the verification right, `coEvery` for the suspend call included, is the junior bar. From middle level up you are expected to explain the machinery underneath: the stubbing block runs under a call recorder, final classes are mocked by instrumenting their bytecode rather than by subclassing, and `mockkObject` patches the real singleton in place, which is why a test that passes alone can fail when the whole suite runs. Senior conversations then turn to policy: when an ordered verification pins incidental behavior, whether exhaustive checks earn their noise, and when a hand-written fake beats another mock.
It opens on the theory MockK puts into code. The [kinds of test double](/topics/found-testing-doubles) supply the words every later answer uses, stub, spy and verified interaction among them, and [test isolation](/topics/found-testing-isolation) comes this early because so many MockK failures turn out to be state left behind by an earlier test. [Everyday usage](/topics/lang-kotlin-testing-mockk) follows: the first stub, the first verification and the first coroutine mock, at the depth a working test needs. The middle of the plan takes the library apart in the order a test is written. Creating a double opens with Kotlin's [final-by-default classes](/topics/lang-kotlin-classes-open-final), the reason MockK instruments classes at all, before [mocks and spies](/topics/dev-mockk-mocks-spies) and their reset rules. Giving them behavior follows, from return chains to the [answers API](/topics/dev-mockk-stubbing-answers); then the arguments, where [matcher scoping](/topics/dev-mockk-matchers-capture-scoping) explains most of the errors MockK prints; then [verification](/topics/dev-mockk-verification), whose ordered and exhaustive forms decide how brittle a suite becomes. The plan then turns to the Kotlin shapes that have no direct Java counterpart. Kotlin's [companion objects](/topics/lang-kotlin-classes-companion-object) and [top-level functions](/topics/lang-kotlin-functions-top-level) sit directly before [object, static and constructor mocking](/topics/dev-mockk-kotlin-constructs), because a stub on a singleton or an extension function only makes sense once you know what the compiler turned it into. It ends with time and wiring: [coroutine testing](/topics/lang-kotlin-testing-coroutine) and JUnit's [extension callbacks](/topics/dev-junit-extensions-callbacks) come ahead of MockK's suspend mocking, its annotations and its [JUnit 5 extension](/topics/dev-mockk-coroutines-annotations-junit5), since that extension is itself a set of callbacks.
If you have written a few MockK tests and the interview is close, start with the everyday-usage module, then raise importance to must know and work the stubbing, matcher and verification modules by frequency. Middle and senior candidates should narrow level to their range and spend their time on mock lifecycle, object and static mocking and exhaustive verification, where the questions are about suites rather than single tests. Coming from Mockito, switch study order to by topics and read the Kotlin modules with care: they hold most of what does not carry over. Kotlin itself appears here only where mocking leans on it, and assertions, spec styles and property tests are not covered at all. For the loop around this library, the [Kotlin Backend Developer roadmap](/roadmaps/kotlin-developer) places it beside Spring, coroutines and the rest of the JVM test stack; for the test framework many MockK suites run inside, see the [Kotest roadmap](/roadmaps/kotest).
MockK rarely gets a round of its own. It surfaces inside the testing conversation of a Kotlin backend or Android loop, often as a test you are asked to write or repair on the spot: a service with two collaborators, one of them a suspend repository, and a bug the test should catch. Interviewers then pull on the details. Why does a call nobody stubbed throw on a plain mockk<T>() but quietly return a default on a relaxed one? Why will any() not compile outside an every or verify block, and why does mixing a matcher with a plain literal sometimes break? What string does mockkStatic need before it can stub a top-level function?
The levels part on how far down the explanation reaches. Getting the stub and the verification right, coEvery for the suspend call included, is the junior bar. From middle level up you are expected to explain the machinery underneath: the stubbing block runs under a call recorder, final classes are mocked by instrumenting their bytecode rather than by subclassing, and mockkObject patches the real singleton in place, which is why a test that passes alone can fail when the whole suite runs. Senior conversations then turn to policy: when an ordered verification pins incidental behavior, whether exhaustive checks earn their noise, and when a hand-written fake beats another mock.
It opens on the theory MockK puts into code. The kinds of test double supply the words every later answer uses, stub, spy and verified interaction among them, and test isolation comes this early because so many MockK failures turn out to be state left behind by an earlier test. Everyday usage follows: the first stub, the first verification and the first coroutine mock, at the depth a working test needs.
The middle of the plan takes the library apart in the order a test is written. Creating a double opens with Kotlin's final-by-default classes, the reason MockK instruments classes at all, before mocks and spies and their reset rules. Giving them behavior follows, from return chains to the answers API; then the arguments, where matcher scoping explains most of the errors MockK prints; then verification, whose ordered and exhaustive forms decide how brittle a suite becomes.
The plan then turns to the Kotlin shapes that have no direct Java counterpart. Kotlin's companion objects and top-level functions sit directly before object, static and constructor mocking, because a stub on a singleton or an extension function only makes sense once you know what the compiler turned it into. It ends with time and wiring: coroutine testing and JUnit's extension callbacks come ahead of MockK's suspend mocking, its annotations and its JUnit 5 extension, since that extension is itself a set of callbacks.
If you have written a few MockK tests and the interview is close, start with the everyday-usage module, then raise importance to must know and work the stubbing, matcher and verification modules by frequency. Middle and senior candidates should narrow level to their range and spend their time on mock lifecycle, object and static mocking and exhaustive verification, where the questions are about suites rather than single tests. Coming from Mockito, switch study order to by topics and read the Kotlin modules with care: they hold most of what does not carry over.
Kotlin itself appears here only where mocking leans on it, and assertions, spec styles and property tests are not covered at all. For the loop around this library, the Kotlin Backend Developer roadmap places it beside Spring, coroutines and the rest of the JVM test stack; for the test framework many MockK suites run inside, see the Kotest roadmap.