Kotlin lambda 回调的单元测试
2022-09-02 13:12:58
假设我们有以下函数要测试
fun loadData(dataId: Long, completion: (JsonElement?, Exception?) -> Unit) {
underlayingApi.post(url = "some/rest/url",
completion = { rawResult, exception ->
val processedResult = processJson(rawResult)
completion(processedResult, exception)
})
}
我很清楚如何模拟,注入,存根和验证对的调用。underlayingApi
如何验证返回的结果? completion(processedResult, exception)