In this recipe, we are going to explore how to effectively test code that uses coroutines internally. We are going to write a unit test for the part of a code that runs asynchronously in the background while trying to authorize the given user credentials using an external API. We are going to employ the Kotlin Mockito library to mock the calls to the external API and the TextCoroutineContext class, allowing us to test asynchronous code with ease.
Unit tests for Kotlin coroutines
Getting ready
We are going to use the JUnit library to provide the core framework for running test-case classes. We need to add it to our project's list of project dependencies by declaring it in the gradle.build script:
implementation group:...