最终在 Kotlin Kotest 中处理多个异常

问题描述

根据 kotest 文档:https://github.com/kotest/kotest/blob/master/doc/nondeterministic.md

您可以告诉 eventually 忽略特定异常,其他任何异常都会立即通过测试。

我想将多个异常传递给最终我知道我的块会抛出的异常,以便我可以明确跳过它们。

现在我只看到一种方法来传递一个,如果块抛出这些异常,我如何将多个异常传递给 eventually 以跳过它?

解决方法

您可以对所有异常使用超类,例如

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

或包装异常

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

4.4.3中没有异常集合的特征

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...