Junit test Rxjava method

后端 未结 1 1024
囚心锁ツ
囚心锁ツ 2021-01-26 06:04

I tested the Rxjava methods many times without problem but now i faced with this problem : Null pointer exception

相关标签:
1条回答
  • 2021-01-26 06:56

    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")
    }
    }
    
    0 讨论(0)
提交回复
热议问题