Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
class MainViewModel(
private val dispatcher: CoroutineDispatcher
) : ViewModel() {
private var _userData: MutableLiveData<Any> = MutableLiveData<Any>()
val userData: LiveData<Any> = _userData
suspend fun saveSessionData() {
viewModelScope.launch(dispatcher) {
_userData.value = "some_user_data"
class MainViewModelTest {
private val testDispatcher = TestCoroutineDispatcher()
var mainCoroutineRule = MainCoroutineRule()
fun testsSaveSessionData() = runBlockingTest {
val mainViewModel = MainViewModel(testDispatcher)
val userData = mainViewModel.userData.value
assertEquals("some_user_data", userData)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment