You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When running a testcase, it fails and in the stacktrace shows the following trace:
kotlinx.coroutines.test.UncaughtExceptionsBeforeTest: There were uncaught exceptions before the test started. Please avoid this, as such exceptions are also reported in a platform-dependent manner so that they are not lost.
at app//kotlinx.coroutines.test.TestScopeImpl.enter(TestScope.kt:239)
at app//kotlinx.coroutines.test.TestBuildersKt__TestBuildersKt.runTest-8Mi8wO0(TestBuilders.kt:309)
at app//kotlinx.coroutines.test.TestBuildersKt.runTest-8Mi8wO0(Unknown Source)
at app//kotlinx.coroutines.test.TestBuildersKt__TestBuildersKt.runTest-8Mi8wO0(TestBuilders.kt:168)
at app//kotlinx.coroutines.test.TestBuildersKt.runTest-8Mi8wO0(Unknown Source)
at app//kotlinx.coroutines.test.TestBuildersKt__TestBuildersKt.runTest-8Mi8wO0$default(TestBuilders.kt:160)
at app//kotlinx.coroutines.test.TestBuildersKt.runTest-8Mi8wO0$default(Unknown Source)
/* test case: */classSettingsViewModelTest {
@get:Rule
val mainDispatcherRule =MainDispatcherRule()
privatelateinitvar viewModel:SettingsViewModel
@MockK
privatelateinitvar preferencesDataStore:DataStore<Preferences>
@Before
funsetup() {
MockKAnnotations.init(this)
}
@Test
fun`Should return default settings from local storage`() = runTest {
coEvery { preferencesDataStore.data } returns flowOf(emptyPreferences())
viewModel =SettingsViewModel(UserPreferencesRepository(preferencesDataStore))
val uiState = viewModel.uiState.first()
assertNotNull(uiState)
when (uiState) {
isSettingsUiState.Success-> {
assertNotNull(uiState.settings)
assertFalse(uiState.settings.useDarkTheme)
assertTrue(uiState.settings.useDynamicColor)
assertTrue(uiState.settings.isOnboarding)
}
else-> fail()
}
}
}
In this scenario, im trying to mock the DataStore, the testcase is configured with mockk library, and, when running the testcase using junit4, it fails woth the stacktrace showing the UncaughtExceptionsBeforeTest Detail.
The text was updated successfully, but these errors were encountered:
Please look at the list of the exceptions suppressed by the UncaughtExceptionsBeforeTest and make sure these exceptions aren't thrown. These can also be exceptions that come from other tests but weren't caught in time, because they happened after the execution had already left their runTest block.
This exception happened with me you need to check stubbing data you need to check before initializing the viewmodel you are stubbing if you have something in init block
the error may came from other tests not this test that referenced in the logcat
What happened? What should have happened instead?
When running a testcase, it fails and in the stacktrace shows the following trace:
Provide a Reproducer
Im using a class name Main
In this scenario, im trying to mock the DataStore, the testcase is configured with mockk library, and, when running the testcase using junit4, it fails woth the stacktrace showing the
UncaughtExceptionsBeforeTest
Detail.The text was updated successfully, but these errors were encountered: