Code Coverage Inline Function

2.9k views Asked by At

i have this function written in 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)
            }
        }
}

But when i created unit tests for this function, it shows 0 coverage on the report. I am using jacoco for code coverage. Do you guys know how to unit test inline function properly? Thanks!

1

There are 1 answers

3
voddan On BEST ANSWER

Since the code is inlined, there are no calls to this function in your tests, and jacoco thinks that you never use it.

A piece of advice: forget about test coverage, it is totally useless. A project can have great tests and 30% coverage. Or someone can spend a ton of time to get 100% coverage, and still have dozens of bugs in production. I've seen both.