What do I do to make kotest print stacktrace with ...
# kotest
k
What do I do to make kotest print stacktrace with the root cause of the assertion error? 🧵
My test looks like this:
I have a proper assertion failure at
requestMessage.shouldBeEqual
based on an implementation change, but the stacktrace doesn't include the actual call where the assertion failed, why?
I get a stacktrace like this leading to nowhere...
k
Not sure I understand where coroutines are involved here in my assertion?
Copy code
requestMessage.shouldBeEqual("...")
Is the failing assertion,
requestMessage
is a String. Or are you saying that's just how all kotest failure look like because
test
are using coroutines?
s
The latter yes. All tests in Kotest run inside a coroutine.
k
It sounds like the problem is due to some
toString()
method that turns
HttpMethod(value=POST)
into just
"POST"
. That seems to be the only difference. By the way, what is
shouldBeEqual
? It doesn't seem to be part of Kotest.
k
shouldBeEqual
is a kotest matcher
In my example
requestMessage
is a
String
, so I'm basically doing
someString.shouldBeEqual(otherString)
k
That's strange, I can see that it does indeed exist, but it doesn't appear to be documented (except as a prefix to the function named
shouldBeEqualComparingTo
) and I've always tested for equality using the shorter name
shouldBe
. Also, it sounds ungrammatical: "a shouldBeEqual b" doesn't sound like proper English; it should be either "a shouldEqual b" or "a shouldBeEqualTo b".
s
should be equal doesn't special case, it literally uses the equals method
but shouldBe will take into account things like arrays
thank you color 1
k
Anything can be done here to produce a normal stacktrace without having to hook up a bunch of debugging tooling?
c
If you add
Copy code
try {
    ...
} catch (e: Exception) {
    throw RuntimeException("Spied exception", e)
}
it'll ensure that at least that specific place appears in the stacktrace.
Using kotlinx-coroutines-debug should just mean adding the dependency and running with
-ea
though, it shouldn't be too hard