Created
February 24, 2021 14:24
-
-
Save prokash-sarkar/dffbe1df8ad4e325dd9e5ac1817390ec to your computer and use it in GitHub Desktop.
This file contains hidden or 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 : 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() | |
@Test | |
fun testsSaveSessionData() = runBlockingTest { | |
val mainViewModel = MainViewModel() | |
mainViewModel.saveSessionData() | |
val userData = mainViewModel.getUserData() | |
assertEquals("some_user_data", userData) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment