Created
February 24, 2021 14:27
-
-
Save prokash-sarkar/d0bcbb9d4e4040b1ffd1ff188c1e40df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | |
} | |
} | |
} | |
@ExperimentalCoroutinesApi | |
class MainViewModelTest { | |
private val testDispatcher = TestCoroutineDispatcher() | |
@ExperimentalCoroutinesApi | |
@get:Rule | |
var mainCoroutineRule = MainCoroutineRule() | |
@Test | |
fun testsSaveSessionData() = runBlockingTest { | |
val mainViewModel = MainViewModel(testDispatcher) | |
mainViewModel.saveSessionData() | |
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