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.

Version

  • 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.

1

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

2

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.

3

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

4

Advanced Mocking

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

5

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

6

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

7

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

8

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.

9

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
  • Mocking private functions
  • Creating partial mocks via spies
  • Mocking suspending calls
  • Verifying methods are called
  • Capturing and replaying arguments

Contributors

Comments