Skip to content

Instantly share code, notes, and snippets.

@cp-radhika-s
Created December 22, 2021 06:32
Show Gist options
  • Save cp-radhika-s/7f7614310f06fecfe33154d3201417f4 to your computer and use it in GitHub Desktop.
Save cp-radhika-s/7f7614310f06fecfe33154d3201417f4 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 `Failure state works`() = runBlocking {
whenever(userServices.getUsers()).thenThrow(RuntimeException("Error"))
viewModel = MainViewModel(userServices, testDispatcher)
Assert.assertEquals(State.FAILURE("Error"), viewModel.state.value)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment