TestCoroutineRule

Additional

Language
Kotlin
Version
1.0.1 (Jul 7, 2019)
Created
Jul 6, 2019
Updated
Jul 12, 2019 (Retired)
Owner
Marcin (marcinOz)
Contributor
Marcin (marcinOz)
1
Activity
Badge
Generate
Download
Source code
APK file

Show card

TestCoroutineRule

TestCoroutineRule library to simplify testing of coroutines, based on idea from Google IO talks: https://youtu.be/BOHK_w09pVA?t=2018.


@get:Rule
val testCoroutineRule = TestCoroutineRule()

@Test
fun `testing suspend function`() = testCoroutineRule.runBlockingTest {
    val result = someSuspendFunction()
    assertEquals(result, 44)
}

Step 1. Add the JitPack repository to your build file
Add it in your root build.gradle at the end of repositories:

allprojects {
  repositories {
    ...
    maven { url 'https://jitpack.io' }
  }
}

Step 2. Add the dependency (in build.gradle under app)

dependencies {
  testImplementation 'com.github.marcinOz:TestCoroutineRule:1.0.1'
}