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.

5
  • What's your DayOfWeek structure Commented May 24, 2019 at 15:37
  • sealed class DayOfWeek( val dayOfWeek: Int, val shortName: String, val fullName: String ) Note I'm also having this problem on my new file where I'm trying to sort this ArrayList<Pair<Double, BarcodeImageAnalyzerResult>> .sortBy { distanceAndBarcode -> distanceAndBarcode.first } Commented May 24, 2019 at 18:38
  • What happens if you use Jacoco? Commented May 25, 2019 at 9:41
  • Any updates for this issue yet? Commented Jun 25, 2020 at 8:49
  • Not that I've seen, but I haven't tried in Kotlin 1.4 Commented Jun 26, 2020 at 2:06

1 Answer 1

8
+50

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.