kotlin and ArgumentCaptor - IllegalStateException

后端 未结 8 1360
长发绾君心
长发绾君心 2020-12-30 18:44

I have a problem with capturing the Class argument via ArgumentCaptor. My test class looks like this:

@RunWith(RobolectricGradleTestRunner::class)
@Config(sd         


        
8条回答
  •  半阙折子戏
    2020-12-30 19:07

    As stated by CoolMind in the comment, you first need to add gradle import for Kotlin-Mockito and then shift all your imports to use this library. Your imports will now look like:

    import com.nhaarman.mockitokotlin2.argumentCaptor
    import com.nhaarman.mockitokotlin2.any
    import com.nhaarman.mockitokotlin2.eq
    import com.nhaarman.mockitokotlin2.isNull
    import com.nhaarman.mockitokotlin2.mock
    import com.nhaarman.mockitokotlin2.verify
    

    Then your test class will be something like this:

    val mArgumentCaptor = argumentCaptor()
    
    @Test
    fun signUp_success() {
        val customer = Customer().apply {
            name = "Test Name"
            email = "test@example.com"
            phone = "0123444456789"
            phoneDdi = "+92"
            phoneNumber = ""
            countryCode = "92"
            password = "123456"
        }
        mPresenter.signUp(customer)
        verify(mView).showProgress()
        verify(mInteractor).createAccount(any(), isNull(), mArgumentCaptor.capture())
    }
    

提交回复
热议问题