Closed kirillzh closed 3 weeks ago
For clue support, it is not the type of exception that matters. Kotest actually relies on inserting the clue message at throw time, which it does via this function:
fun failure(message: String, cause: Throwable?): AssertionError {
return Exceptions.createAssertionError(clueContextAsString() + message, cause)
}
To work around this restriction, you could use something like this withClues function (note the plural form).
But I wonder whether we could switch to make augmenting exceptions by intermediate catch blocks the default in Kotest. We'd need to look at how that influences stack traces. Also, clues could look a bit nicer and have their message appear visually separated.
Kotest version: 5.9.0
Consider test:
On failure a clue is not printed:
Expected something like:
I suspect this is because
asClue
andwithClue
only work when the block throws kotest'sAssertionFailedError
. And becausesingle
throws kotlin'sNPE
orIllegalArgumentException
, it doesn't work nicely with clues.In many cases, our tests and testing infrastructure performs assertions without using kotest APIs (using methods like
single
,first
, etc that throw nonAssertionFailedError
exceptions). Because of this, majority of our test failures are missing clues.It would be very helpful if
asClue
/withClue
worked still when any exception is throws.Slack
kotlinlang
discussion: https://kotlinlang.slack.com/archives/CT0G9SD7Z/p1726702539652919