11

I'm writing some unit tests for my Android app written in Kotlin, and I'm getting errors from the included inlined collection functions, in this case specifically sortedBy

 override fun onDaysSelected(dayOfWeekList: ArrayList<DayOfWeek>) {
        view.userRoutingRule.days = dayOfWeekList.sortedBy { it.dayOfWeek }
        renderRule()
 }

This is the error I'm getting when I run my unit tests with coverage

---- IntelliJ IDEA coverage runner ---- sampling ... include patterns: com.mypackage..* exclude patterns:[2019.02.02 14:49:40] (Coverage): Class data was not extracted: com.mypackage\myfile$onDaysSelected$$inlined$sortedBy$1: java.lang.Throwable

Process finished with exit code 0

My unit tests all pass accordingly, but when I go to look at the coverage report, it's almost completely bare as this error stopped it from completing.

Is there any solution to this at this point? It's hard to know if I missed some condition if I can't just look at the report.

Ben987654
  • 3,280
  • 4
  • 27
  • 50

1 Answers1

8

It's a known issue with calculating coverage of imline methods that use lambdas. (see No coverage report for inlined Kotlin methods and https://discuss.kotlinlang.org/t/inline-functions-coverage/5366)

If you want to run coverage in the current state, you'll need to use other approaches, for example implementing Comparable interface in your DayOfWeek and using .sorted() method.

TpoM6oH
  • 8,385
  • 3
  • 40
  • 72