【发布时间】:2019-05-03 17:05:27
【问题描述】:
我只是想检查用户是否是使用异步方法创建的,我是测试新手,我正在使用 ArgumentCaptor 检查是否调用了 onRegistrationSucces() 回调 1 次来检查它成功了。
这就是我所做的测试
RegisterTest.kt
@Test
fun should_SignUpUser(){
presenter.signUp("test1","test1@gmail.com","asdasd")
verify(interactor).createUserWithEmailAndPassword("test1","test1@gmail.com","asdasd",object: RegisterInteractor.RegisterCallBack{
override fun onRegistrationSucces() {
callbackCaptor.capture()
}
override fun onRegistrationFailure(errorMsg: String) {
callbackCaptor.capture()
}
})
verify(callbackCaptor.value.onRegistrationSucces(), times(1))
}
这是我正在尝试测试的演示者方法
RegisterPresenter.kt
override fun signUp(fullName:String, email: String, password: String) {
view?.showProgress()
registerInteractor.createUserWithEmailAndPassword(fullName,email, password, object : RegisterInteractor.RegisterCallBack {
override fun onRegistrationSucces() {
if(isViewAttached()){
view?.navigateToLogin()
view?.hideProgress()
}
}
override fun onRegistrationFailure(errorMsg:String) {
if(isViewAttached()){
view?.showError(errorMsg)
view?.hideProgress()
}
}
})
}
但是我收到了这个错误
参数不同!通缉: interactor.createUserWithEmailAndPassword( “测试1”, "test1@gmail.com", “asdasd”, com.testapp.presentation.register.presenter.RegisterPresenterTest$should_SignUpUser$1@c86b9e3 ); -> 在 com.testapp.presentation.register.presenter.RegisterPresenterTest.should_SignUpUser(RegisterPresenterTest.kt:119) 实际调用有不同的参数: interactor.createUserWithEmailAndPassword( “测试1”, "test1@gmail.com", “asdasd”, com.testapp.presentation.register.presenter.RegisterPresenter$signUp$1@10aa41f2 ); -> 在 com.testapp.presentation.register.presenter.RegisterPresenter.signUp(RegisterPresenter.kt:64)
【问题讨论】:
标签: android unit-testing kotlin