Skip to content

Instantly share code, notes, and snippets.

@cp-radhika-s
Created December 22, 2021 06:34
Show Gist options
  • Save cp-radhika-s/8da20a08c455ffef49e50e7c4e4635b4 to your computer and use it in GitHub Desktop.
Save cp-radhika-s/8da20a08c455ffef49e50e7c4e4635b4 to your computer and use it in GitHub Desktop.
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