Created
December 22, 2021 06:32
-
-
Save cp-radhika-s/7f7614310f06fecfe33154d3201417f4 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 `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