Open eboudrant opened 3 years ago
Thanks for flagging, possibly the coroutines are not configured correctly for tests? Could you share how you are using MvRxTestRule
?
The only thing we are doing with the test rule is declaring it at the top of the class :
@get:Rule
val mvRxTestRule = MvRxTestRule()
If you look in the src of MvRxTestRule you'll see it is partially a helper for initializing Mavericks
private fun setupMocking() {
val mocksEnabled = viewModelMockBehavior != null
// Use a null context since we don't need mock printing during tests
MockableMavericks.initialize(debugMode = debugMode, mocksEnabled = mocksEnabled, applicationContext = null)
if (viewModelMockBehavior != null) {
MockableMavericks.mockConfigFactory.mockBehavior = viewModelMockBehavior
}
}
However, this does not set any coroutine overrides for the options of subscriptionCoroutineContextOverride
stateStoreCoroutineContext
or viewModelCoroutineContext
on MockableMavericks.initialize
You may want to play around with setting these to either the testDispatcher: CoroutineDispatcher = TestCoroutineDispatcher()
in the test rule, or to Dispatchers.Unconfined.
Particularly stateStoreCoroutineContext
may be needed to be set to a controlled dispatcher for your case, since otherwise it uses a private thread pool. The other contexts should default to the main thread.
Since we migrated from MvRx 1.5 to Mavericks 2.0 we observe intermittent failures in our unit test. We are still using the
mavericks-rxjava
library. I just wanted to open an issue here in case someone observed the same behavior.We're using robolectric 4.5-alpha-3 and mockito 3.8.0.
The code where it happen :
OurViewModel.kt
In the test class we use the
MvRxTestRule
but I suspect some processes are still running async causing theses issues in Mockito. Ex, some of the.execute {
run on this thread during testing :Thread[pool-5-thread-2 @coroutine#7,5,SDK 21]
And we have theses warnings:
We are still investigating...