https://kotlinlang.org logo
Title
k

Kirill Zhukov

05/17/2023, 9:51 PM
Is there a way to make kotest failures to always print the line number where matcher failed? For example, in a simple test like this it’s not obvious which lined failed exactly:
fun a(): Any = 1
fun b(): Any = ""

test("foo") {
  a().shouldBeTypeOf<String>()
  b().shouldBeTypeOf<String>()
}
output:
1 should be of type kotlin.String
Sometimes I do see kotest print full stacktrace with line number but not in this case for some reason
e

Emil Kantis

05/17/2023, 9:56 PM
Works for me, both when run through gradle and kotest runner (intellij)
what platform are you testing on?
k

Kirill Zhukov

05/17/2023, 10:52 PM
KMP, tried targeting JVM and Android
host platform? mac OS
when running from CLI using gradle task:
....SomeTests[jvm] > foo[jvm] FAILED
    java.lang.AssertionError: 1 should be of type kotlin.String
        at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:78)
        at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:167)
        at ....
Is there something off in my build config setup?
e

Emil Kantis

05/17/2023, 11:19 PM
Hard to tell from just looking at this.. I think
shouldBeTypeOf
inlines code, and perhaps when running from CLI that is not translated properly into a good stacktrace. Can you try running from intellij?
k

Kirill Zhukov

05/17/2023, 11:26 PM
I originally discovered this problem in IJ (well, Android Studio) 🙂