Testing With MockK

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

Leave a rating/review
Save for later
Comments
Share

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

Part 1: MockK: The Basics

01
Toggle description

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

Toggle description

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

Toggle description

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.

Toggle description

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

Part 2: Advanced Mocking

Toggle description

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

Toggle description

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

Toggle description

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

Toggle description

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

Toggle description

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.