Skip to content

Instantly share code, notes, and snippets.

@weverb2
Created January 22, 2019 01:35
Show Gist options
  • Save weverb2/a8de3418b6c493c10085c3fe382fb2c7 to your computer and use it in GitHub Desktop.
Save weverb2/a8de3418b6c493c10085c3fe382fb2c7 to your computer and use it in GitHub Desktop.
class MainViewModelTest {
@get:Rule
val instantTaskRule = InstantTaskExecutorRule()
@RelaxedMockK
lateinit var mockObserver: Observer<Boolean>
lateinit var viewModel: MainViewModel
@Before
fun setUp() {
MockKAnnotations.init(this)
viewModel = MainViewModel()
}
@Test
fun testValidation() {
viewModel.isFormValid.observeForever(mockObserver)
viewModel.username = "username1"
viewModel.password = "password1"
viewModel.username = "username"
verifyOrder {
mockObserver.onChanged(false)
mockObserver.onChanged(true)
mockObserver.onChanged(false)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment