Session

Understanding mocks and spies using mockk

Mocks and spies form a vital tool for unit, integration and end-to-end tests. But a lot of potential use-cases are sometimes lost in the jargon, with questions like: Is it a stub? What is a fake? Why can't we directly use the real objects? etc.

While these questions seem to be valid and they do attract the spotlight, the core fundamentals behind mocking and spying seem to lose focus.

In this talk we'll cover the journey of re-understanding these core concepts from an implementation point of view, while putting focus on the following points:
* What are test doubles and why are they called so?
* Types of test doubles and busting the jargon with simple definitions.
* Introduction to mockk.io and its Kotlin first nature.
* Mocking and Stubbing in context of mockk.
* Mocking vs Spying with real life examples on which one to use when & why with working code snippets around the same. Canned responses and why we need them.
* Mocking private calls and implementation hurdles.
* Mocking extension functions. Moving away from the OO nature of mocking.
* Shortcomings, problems and troubleshooting them by understanding how the internals works.
* Advanced features: Verification - ordered, unordered. Answers and exclusions, Capturing, Operations, coroutine support, properties support.
* Unmocking.
* Links, documentations and cheat-sheets.

While some real life examples originate from backend applications, listeners in no way need to be aware of any backend context. This topic is Kotlin first and conceptually deep dives into mocking and spying as a concept. The listeners are not expected to have prior knowledge of testing or are expected to have written mocks or spies before.
Mockk is just one of the tools for mocking available. And the choice for using mockk as the basis for the explanation of these concepts is a personal decision and wasn't sponsored.

Suraj Shah

Technical Lead, SuperShare

Bengaluru, India

Please note that Sessionize is not responsible for the accuracy or validity of the data provided by speakers. If you suspect this profile to be fake or spam, please let us know.

Jump to top