-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
java.lang.NoSuchMethodError: kotlinx.coroutines.SupervisorKt.SupervisorJob #1331
Comments
Full log:
|
What's your environment? How do you get this problem? |
What exactly do you mean by environment? Also another thing - I made it work by injecting the dispatcher. Meaning it won't work without injecting the CoroutineDispatcher, correct me if I'm wrong? |
came across this on the github page |
Does it mean that whenever I need to use Dispaters.IO or Dispatcher.Default I have to provide it using dependency injection so that I can test it in the future? Or I incorrect get it? |
It depends on your testing strategy. |
Same issue here
@Test
fun `test login behavior`() = runBlockingTest {
userRepository.login(USERNAME, PASSWORD)
coVerify {
val user = remoteUserDao.login(USERNAME, PASSWORD)
localUserDao.insert(user)
}
} class UserRepositoryImpl(
private val remoteUserDao: RemoteUserDao,
private val localUserDao: LocalUserDao
) : UserRepository {
override suspend fun login(username: String, password: String): User {
val user = remoteUserDao.login(username, password)
localUserDao.insert(user)
return user
}
} Kotlin version: 1.3.41 |
Can you, please, check that your |
In my case, using
every time throws error:
on every version My Kotlin plugin version: |
Does your version of |
I thought |
@JakubMosakowski Is there any chance you can create and share a small project that would demonstrate the problem that you are experiencing? |
Sure, here it is: https://github.com/JakubMosakowski/test-project-coroutines
|
FWIW I'm hitting the same issue. Backporting to org.jetbrains.kotlinx:kotlinx-coroutines-test:1.2.2 seems to resolve the issue for me until a root cause is known. |
LiveData + kotlin coroutine system. This introduces a custom LiveData to mediate between Kotlin coroutines in a way that allows tests to actually ensure the coroutines resolve quickly, and ensure lifecycle safety through standard LiveData mechanisms. However, this doesn't actually fix the underlying tests (which have been changed in a number of ways in this commit in an effort to try and get them to pass). The kotlinx coroutine deps were downgraded to work around a NoSuchMethodError (see Kotlin/kotlinx.coroutines#1331). After introducing a runBlockingTest structure and updating the user app histoyr controller to use the test context, the operations seem to work correctly. However, one job is hanging which is causing the test to still fail (it appears to be deadlocked--no known amount of time allows it to resolve). This new NotifiableAsyncLiveData also appears to break the production behavior, as well. The LiveData result is no longer being observed by the data binding transformation function, so it seems the coroutines aren't being executed, aren't completing, or something is deadlocking somewhere. Further investigation is needed.
The problem here is not in the library itself but in transitive dependencies. How to verify you have this problemIn Android Studio or IntelliJ IDEA press How to resolve the problemYou have multiple options here:
@JakubMosakowski thanks for the reproducer! |
* Migrate ListenableFuture to a Kotlin coroutine, and split HomeActivity into both an activity and a fragment. * Introduce the domain and testsupport modules. The domain module includes a user app history controller that provides instances of a new AsyncResult interface that's meant to be a potential bridge between Kotlin coroutines and LiveData. The exact design of how this should work needs to be determined as part of #6. This also includes a new testsupport module that's required due to robolectric/robolectric#4736. This is supporting a new test for the app history controller that leverages an AndroidX activity scenario to test the live data. Note that the test does not yet work since there's a race condition between the LiveData's coroutines completing and the test continuing to verify the state of the activity. This needs to be resolved, likely by waiting for test visual elements to change based on the LiveData result. Additional tests need to be added for other new components, and some slight cleaning up may be necessary. * Fix binary build: testsupport should only be depended on for tests, not for production configurations. * 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 tests to actually ensure the coroutines resolve quickly, and ensure lifecycle safety through standard LiveData mechanisms. However, this doesn't actually fix the underlying tests (which have been changed in a number of ways in this commit in an effort to try and get them to pass). The kotlinx coroutine deps were downgraded to work around a NoSuchMethodError (see Kotlin/kotlinx.coroutines#1331). After introducing a runBlockingTest structure and updating the user app histoyr controller to use the test context, the operations seem to work correctly. However, one job is hanging which is causing the test to still fail (it appears to be deadlocked--no known amount of time allows it to resolve). This new NotifiableAsyncLiveData also appears to break the production behavior, as well. The LiveData result is no longer being observed by the data binding transformation function, so it seems the coroutines aren't being executed, aren't completing, or something is deadlocking somewhere. Further investigation is needed. * Fix the app not properly binding to the live data by ensuring the data binder had the view model set properly. Fix resource binding issues in Robolectric tests by ensuring binary resources are provided to Robolectric. Fix the controller tests not working by introducing a temporary, custom CoroutineLiveData that ensures no long-living jobs continue running after the live data is completed. * Clean up tests (we no longer need a testsupport module for this module introduction). * Add test for AsyncResult. Set code style for Groovy files & clean up all build gradle files. Add missing newlines at end of various files. * Reformat top-level build.gradle file, as well. * Address review comments: replace name-based TODOs with issues. * Address review comments: add EOF new lines.
Just in case anyone else ends up here with this issue and finds that adding the
|
Trying to use
runBlockingTest
for my unit tests, and getting the above-mentioned error.Here are my code snippets:
Also getting the same error when trying to use TestCoroutineDispatcher.
The text was updated successfully, but these errors were encountered: