kotest-assertions / io.kotest.assertions / assertSoftly

assertSoftly

inline fun <T> assertSoftly(assertions: () -> T): T

Run multiple assertions and throw a single error after all are executed if any fail

This method will run all the assertions inside assertions block, and will collect all failures that may happen. It then compact all of them in a single throwable and throw it instead, or nothing if no assertion fail.

    // All assertions below are going to be executed, even when one or multiple fail.
    // All the failures are then collected and thrown in one single throwable.
    assertSoftly {
        "foo" shouldBe "bar"
        "foo" shouldBe "foo
        "foo" shouldBe "baz"
    }