Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Kotlin 如何使用高阶函数参数测试方法?_Kotlin_Mockito_Tdd - Fatal编程技术网

Kotlin 如何使用高阶函数参数测试方法?

Kotlin 如何使用高阶函数参数测试方法?,kotlin,mockito,tdd,Kotlin,Mockito,Tdd,我试着用一个高阶函数作为参数来测试一个方法。 面对这个错误: Argument(s) are different! Wanted: viewContractMock.showError( (fetchUserIdentity_showOptions_failed$2) Function0<kotlin.Unit> ); -> at br.com.fastshop.ecommerce.ui.resetpassword.controller.RecoveryOptionsC

我试着用一个高阶函数作为参数来测试一个方法。 面对这个错误:

Argument(s) are different! Wanted:
viewContractMock.showError(
    (fetchUserIdentity_showOptions_failed$2) Function0<kotlin.Unit>
);
-> at br.com.fastshop.ecommerce.ui.resetpassword.controller.RecoveryOptionsControllerTest.fetchUserIdentity_showOptions_failed(RecoveryOptionsControllerTest.kt:65)
Actual invocation has different arguments:
viewContractMock.showError(
    () Function0<kotlin.Unit>
);
-> at br.com.fastshop.ecommerce.ui.resetpassword.controller.RecoveryOptionsController$observeLive$2.onChanged(RecoveryOptionsController.kt:29)
这里是从应用程序调用我的方法的地方:

        recoveryOptionsUseCase.userIdentityLive.observe({ lifecycle }) {
        when (it.status) {
            ResourceState.LOADING -> {
                if (it.loading) {
                    viewContract.showLoading()
                } else {
                    viewContract.hideLoading()
                }
            }
            ResourceState.SUCCESS -> {
                viewContract.bindOptions()
            }
            ResourceState.ERROR -> viewContract.showError(it.callback!!)
        }
    }

你的问题是什么?@takendarkk我不知道如何传递
(fetchUserIdentity\u showOptions\u failed$2)Function0
作为一个匹配程序查看你的代码你必须传递你放在里面的内容
it.callback
我使用mockito kotlin的argumentCaptors修复它
        recoveryOptionsUseCase.userIdentityLive.observe({ lifecycle }) {
        when (it.status) {
            ResourceState.LOADING -> {
                if (it.loading) {
                    viewContract.showLoading()
                } else {
                    viewContract.hideLoading()
                }
            }
            ResourceState.SUCCESS -> {
                viewContract.bindOptions()
            }
            ResourceState.ERROR -> viewContract.showError(it.callback!!)
        }
    }