Created
December 22, 2021 06:34
-
-
Save cp-radhika-s/8da20a08c455ffef49e50e7c4e4635b4 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 MainViewModelTest { | |
@get:Rule | |
val mainCoroutineRule = MainCoroutineRule() | |
private val userServices = mock<UserServices>() | |
private lateinit var viewModel: MainViewModel | |
private val testDispatcher = AppDispatchers( | |
IO = TestCoroutineDispatcher(), | |
MAIN = Dispatchers.Unconfined | |
) | |
@Test | |
fun `Loading state works`() = runBlocking { | |
whenever(userServices.getUsers()).doSuspendableAnswer { | |
withContext(Dispatchers.IO) { delay(5000) } | |
emptyList() | |
} | |
viewModel = MainViewModel(userServices, testDispatcher) | |
Assert.assertEquals(State.LOADING, viewModel.state.value) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment