我最近将一个类从java转换为kotlin,现在我的一个单元测试无法编译。
这是引起它的行:
mockkStatic(PhoneNumberSelectionActivity::class)
every {
PhoneNumberSelectionActivity.startActivity(
mockActivity,
any(),
any()
)
} returns Unit
我的堆栈跟踪:
匹配模拟签名失败SignedCall (retValue = . lang。Void@7a5aa8c5 isRetValueMock = false, retType . lang =类。Void, self=TNActivityBase(mockActivity#1), method=startActivity(Intent), args=[null], invocationStr=TNActivityBase(mockActivity#1).startActivity(null))左匹配器:[any(), any()]
io.mockk。MockKException:匹配mock签名失败SignedCall (retValue = . lang。Void@7a5aa8c5, isRetValueMock=false, retType=class java.lang。Void, self=TNActivityBase(mockActivity#1), method=startActivity(Intent), args=[null], invocationStr=TNActivityBase(mockActivity#1).startActivity(null))左匹配器:[any(), any()]
PhoneNumberSelectionActivity类继承自TNActivityBase。
这是我们试图模拟PhoneNumberSelectionActivity的函数:
fun startActivity(
host: Activity,
phoneExpired: Boolean,
@ACTIVITY_HOST_TYPE activityHostType: Int
) {
if (sIsRunning) {
return
}
sIsRunning = true
val intent = Intent(host, PhoneNumberSelectionActivity::class.java)
intent.putExtra(EXTRA_ACTIVITY_HOST_TYPE, activityHostType)
if (phoneExpired) {
intent.putExtra(EXTRA_SHOW_PHONE_EXPIRE_DIALOG, true)
}
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)
host.startActivity(intent)
}
在我看来,mockkStatic没有做好它的工作。想法吗?
显然mock不支持无符号类型。
与UByteArray匹配mock签名失败,但与ByteArray不匹配
所以我做了:
every {
PhoneNumberSelectionActivity.startActivity(
mockActivity,
true,
PhoneNumberSelectionActivity.ACTIVITY_HOST_TYPE.AUTHORIZATION
)
} returns Unit