6

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!

elsennov
  • 875
  • 9
  • 14
  • This is a Kotlin bug, currently logged here: https://youtrack.jetbrains.com/issue/KT-12605 – Max Nov 09 '17 at 17:24
  • Possible duplicate of [No coverage report for inlined Kotlin methods](https://stackoverflow.com/questions/39817814/no-coverage-report-for-inlined-kotlin-methods) – Manushin Igor Nov 14 '17 at 17:43

1 Answers1

0

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.

voddan
  • 31,956
  • 8
  • 77
  • 87