Vivek Modi
01/26/2022, 10:38 PMinternal fun handleDataResponse() {
dataLiveData.postValue(true)
currentDeviceTypeLiveData.postValue(true)
}
test
@Test
fun `handleDataResponse - Handle connection success `() {
// STUBBING
// EXECUTION
viewModel.handleDataResponse()
// VERIFICATION
assertEquals(true, viewModel.dataLiveData.value)
assertEquals(true, viewModel.currentDeviceTypeLiveData.value)
}
Expected : true
Actual :null
Nikita Voloshin
01/26/2022, 11:19 PMspyk
or stub method call with callOriginal()
. Otherwise, mock will either fail or return null
based on whether it is relaxed or not.
So, make sure your stubbing block contains at least this:
every { viewModel.dataLiveData.postValue(any()) } answers { callOriginal() }
Then, based on your mock creation logic you might need to also stub viewModel.dataLiveData
itself in order to stub get/set
for live data