This course is available as part of the Professional subscription. To learn more click here

Testing With MockK

Oct 15 2019 · Video Course (37 mins) · Intermediate

Learn how and when to use the many powerful features that the MockK Kotlin testing framework provides.


  • Kotlin 1.3, macOS 10.14, Studio 3.4

MockK: The Basics

Get a quick introduction to the Spacing Out project and the NASA api's you'll be using.


Use MockK to create a simple mocked object to help unit test the planet of the day feature.


See how to verify that some interaction happened to an object that you have under test. You'll also learn how to verify that only that interaction happened.


Learn what a partial mock is and how to use spies in MockK to create them.


Advanced Mocking

Coroutines are an easy way to handle asynchronous data. Learn how to mock suspending calls.


Objects are how you represent static values in Kotlin. Learn how and when to dynamically alter their behavior using MockK.


Sometimes you want a mock to return some data that was fed into it. Learn how to accomplish that task by capturing arguments.


Extension functions are amazing, but they can make testing challenging. Learn how to mock different types of extension methods in this lesson.


If your app isn't using dependency injection, it can be challenging to stub and mock out objects. While not ideal, mocking constructors can help.


Who is this for?

This course is for advanced Android developers that are interested in getting up and running with the MockK framework.

It assumes that you're already familiar with the idea behind unit testing and that you've used other mocking frameworks (like Mockito) in the past. It also assumes that you have some familiarity with writing unit and integration tests for Android applications.

Covered concepts

  • Integrating MockK for unit and integration tests
  • Creating simple mocks
  • Mocking extension functions
  • Mocking Kotlin objects
  • Mocking constructors
  • Creating partial mocks via spies
  • Mocking suspending calls
  • Verifying methods are called
  • Capturing and replaying arguments