提问人:vincent 提问时间:11/15/2023 更新时间:11/15/2023 访问量:12
使用接收流的 mockk 进行 Android 单元测试
Android unit testing with mockk that receives flow
问:
我有一个类,它与用例对话并获取流返回 Flow<BaseResponse> 我想对我的 methed deleteDigitalKey 进行单元测试 我是新手使用该流程。需要帮助。这是下面的代码
override fun deleteDigitalKey(): Flow<BaseResponse<Any>> {
return callbackFlow {
TSPDigitalKeyManager.getInstance()
.deleteDigitalKey(mIOVContext.defaultVin) { code, msg ->
specialBleCallBack(code, msg) { codeBack, msgBack ->
trySend(BaseResponse(if (code == 1000) 0 else codeBack, msgBack))
close()
}
}
awaitClose {}
}
}
类 BaseResponse() {
constructor(code: Int = 0, message: String? = null) : this() {
this.code = code
this.msg = message
}
var code: Int? = null
var msg: String? = null
var data: T? = null
fun isSuccess(): Boolean = code != null && code == 0
}
答: 暂无答案
评论