As per kotest docs: https://github.com/kotest/kotest/blob/master/doc/nondeterministic.md
You can tell
eventuallyto 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?
The module kotest-framework-concurrency contains an eventually that allows to specify multiple suppressed exceptions.
There is the possibility to specify a set of exception types:
eventually({
duration = 8000
suppressExceptions = setOf(UserNotFoundException::class)
}) {
userRepository.getById(1).name shouldNotBe "bob"
}
And, there is the possibility to specify a predicate for exceptions:
eventually({
duration = 8000
suppressExceptionIf = { it is UserNotFoundException && it.username == "bob" }
}) {
userRepository.getById(1).name shouldNotBe "bob"
}
Alternatively, you can specify when the test is considered to be in the state that a failure can actually be regarded as failure:
var string = "x"
eventually({
duration = 5.seconds()
predicate = { it.result == "xxx" }
}) {
string += "x"
string
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With