kotlinx.coroutines: java.lang.NoSuchMethodError: kotlinx.coroutines.SupervisorKt.SupervisorJob
Trying to use runBlockingTest for my unit tests, and getting the above-mentioned error.
Here are my code snippets:
@Test
fun `test verify test call`() = runBlockingTest {
registerViewModel.testCall()
verify(repo).suspendedTestCall()
}
fun testCall() {
viewModelScope.launch(Dispatchers.IO) {
repository.suspendedTestCall()
}
}
suspend fun suspendedTestCall() {
kotlinx.coroutines.delay(2_000)
}
Also getting the same error when trying to use TestCoroutineDispatcher.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 2
- Comments: 17 (6 by maintainers)
Commits related to this issue
- Further attempts to try and test the asynchronous behavior of the new LiveData + kotlin coroutine system. This introduces a custom LiveData to mediate between Kotlin coroutines in a way that allows t... — committed to oppia/oppia-android by BenHenning 5 years ago
- Added resolution strategy to fix that issue. https://github.com/Kotlin/kotlinx.coroutines/issues/1331 — committed to JakubMosakowski/test-project-coroutines by JakubMosakowski 5 years ago
- Fix part of #4: Introduce domain module (#64) * Migrate ListenableFuture to a Kotlin coroutine, and split HomeActivity into both an activity and a fragment. * Introduce the domain and testsupport... — committed to oppia/oppia-android by BenHenning 5 years ago
Does your version of
kotlinx-coroutines-testmatches with the version ofkotlinx-coroutines-core?The problem here is not in the library itself but in transitive dependencies.
How to verify you have this problem
In Android Studio or IntelliJ IDEA press
Find symbolhotkey (cmd/ctrl+ N) and typekotlinx.coroutines.Job. If you see more than two versions of the class (example), it’s a dependency clash.How to resolve the problem
You have multiple options here:
kotlinx-coroutines-core(additionally tokotlinx-coroutines-androidorkotlinx-coroutines-testor any other kx-coroutines dependency) with the desired version to your dependencieskotlinx.coroutinesexplicitly using custom Gradle resolution strategy@JakubMosakowski thanks for the reproducer!
Can you, please, check that your
kotlinx-coroutines-coreandkotlinx-coroutines-testversions match.