Skip to content Skip to sidebar Skip to footer

Junit Test Rxjava Method

I tested the Rxjava methods many times without problem but now i faced with this problem : Null pointer exception in this subscribeOn(Schedulers.io()) line. fun registerPhone(phon

Solution 1:

I think you are testing this in wrong way. Try this:

class ViewModelTest : BaseTest() {
    private val mResponseBody = ResponseBody.create(
        null, ""
    )
    private var mGson= Gson()

    private val mRepository = mock()


    @Test
    fun registerPhone_success() {
        whenever(mRepository.getRegister(any())).thenReturn(
            Single.just(
                Response.success(mResponseBody)
            )
        )
        mViewModel.registerPhone("123", "123")
}
}

Post a Comment for "Junit Test Rxjava Method"