我有这个用 Kotlin 编写的函数
inline fun <T> handleEmptyResult(observable: Observable<T>,
crossinline resultEmptyCheckingFunc: (obj: T?) -> Boolean): Observable<T> {
return observable
.flatMap {
if (resultEmptyCheckingFunc(it)) {
Observable.error<T>(ResultEmptyError(Throwable()))
} else {
Observable.just(it)
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我为此函数创建单元测试时,它在报告上显示 0 覆盖率。我正在使用 jacoco 进行代码覆盖。你们知道如何正确地对内联函数进行单元测试吗?谢谢!
假设我有这个功能(用Kotlin编写):
fun determineBottomBarView(assignee: String?,
showChatAssignerFunction: () -> Unit,
showChatComposerFunction: () -> Unit,
hideChatComposerAndAssignerFunction: () -> Unit) {
if (assignee.isNullOrEmpty()) {
showChatAssignerFunction()
} else {
if (assignee.equals(localRequestManager.getUsername())) {
showChatComposerFunction()
} else {
hideChatComposerAndAssignerFunction()
}
}
}
Run Code Online (Sandbox Code Playgroud)
showChatAssignerFunction当受让人为空或空时,是否可以验证(在单元测试中)?谢谢你们!