使用mockito的Kotlin协同程序unit testing

当我尝试模拟和validation一个正在调用暂停function的活动时,我得到了下面的内容

错误:

论据是不同的! 通缉:userManager.getAccountInfo((onCreate_callsGetAccountInformation $ 1)kotlinx.coroutines.experimental.CoroutineScope。() – > kotlin.Unit); – > at com.pharmacy.AccountActivityTests $ onCreate_callsGetAccountInformation $ 1.doResume(AccountActivityTests.kt:117)实际的调用有不同的参数:userManager.getAccountInfo(()kotlinx.coroutines.experimental.CoroutineScope。() – > kotlin.Unit) – > at com.pharmacy.AccountActivity $ loadAccountInfoAsync $ 1 $ 1.doResume(AccountActivity.kt:199)

码:

我有我的unit testing用runBlocking装饰如下所示:

@Test fun onCreate_callsGetAccountInformation() = runBlocking { whenever(userManager.getAccountInfo()).thenReturn(AccountInformation()) subject = Robolectric.setupActivity(AccountActivity::class.java) verify(userManager).getAccountInfo() } 

这里 – > usermanager.getAccountInfo()是一个挂起的函数。

这是mockito版本,2.10及以下版本不支持挂起function。 碰到最新的(2.12)固定它。