小编els*_*nov的帖子

代码覆盖内联函数

我有这个用 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 进行代码覆盖。你们知道如何正确地对内联函数进行单元测试吗?谢谢!

android unit-testing code-coverage inline-functions kotlin

5
推荐指数
1
解决办法
1767
查看次数

单元测试验证通过的函数被调用

假设我有这个功能(用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当受让人为空或空时,是否可以验证(在单元测试中)?谢谢你们!

android unit-testing function verify kotlin

0
推荐指数
1
解决办法
339
查看次数