Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class MainViewModel : ViewModel() {
private var userData: Any? = null
fun getUserData(): Any? = userData
suspend fun saveSessionData() {
viewModelScope.launch(Dispatchers.IO) {
userData = "some_user_data"
}
}
}
@ExperimentalCoroutinesApi
class MainViewModelTest {
@ExperimentalCoroutinesApi
@get:Rule
var mainCoroutineRule = MainCoroutineRule()
@ExperimentalCoroutinesApi
@Test
fun testsSaveSessionData() = runBlockingTest {
val mainViewModel = MainViewModel()
mainViewModel.saveSessionData()
val userData = mainViewModel.getUserData()
assertEquals("some_user_data", userData)
}
}
@venusiza

This comment has been minimized.

Copy link

@venusiza venusiza commented Sep 16, 2021

Would you please share the fragment class for this ViewModel? How dispatcher initialized?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment