assertk
assertk copied to clipboard
Feature to peek into an assertion
I've been adding this simple extension function to peek into my assertions:
fun <T> Assert<T>.peek(peekActual: (T) -> Unit): Assert<T> = apply { given(peekActual) }
I use this function mostly to inspect and print out more detailed messages without stopping the assertion logic flow, for example:
@Test
fun testRaisingAsException() {
assertThat { raise(TransactionError.StopEndOfFile) }
.isFailure().peek { it.printStackTrace() }
.isInstanceOf(TransactionError.TransactionException::class)
}
I would like to contribute back to the community as I feel, even such as simple function has great utility to debug any complex assertion flow.
Thanks - this is very useful!
I also create this method:
fun <T> Assert<T>.value(): T {
given {
return it
}
throw IllegalStateException("This should never be reached")
}