Handle multiple exceptions in Kotlin Kotest eventually

Viewed 504

As per kotest docs: https://github.com/kotest/kotest/blob/master/doc/nondeterministic.md

You can tell eventually to ignore specific exceptions and any others will immediately fail the test.

I want to pass multiple exceptions to eventually that I know would be thrown by my block so that I can explicitly skip them.

Right now I only see a way to pass one, how do I pass more than one exception to eventually to skip it in case the block throws those exceptions?

1 Answers

You may use superclass for all your exceptions like

eventually(200.milliseconds, exceptionClass = RuntimeException::class) {
   throw IllegalStateException()
}

or wrap exceptions

eventually(200.milliseconds, exceptionClass = IllegalStateException::class) {
    runCatching { throw UnknownError() }
        .onFailure { throw IllegalStateException(it) }
}

In 4.4.3 there are no features with collection of Exception

Related