Run multiple assertions with all() and assertAll()
mainYou can group assertions to ensure multiple checks are performed even if one fails.
all { ... }: Use this on a single value to run multiple assertions within a lambda. If any fail, all assertions in the block are executed, and the failure message reports all failures.assertAll { ... }: Use this to wrap multipleassertThatcalls. This ensures that even if oneassertThatfails, the subsequent ones are still executed.
// Multiple assertions on one value
val string = "Test"
assertThat(string).all {
startsWith("L")
hasLength(3)
}
// Multiple independent assertions
assertAll {
assertThat(false).isTrue()
assertThat(true).isFalse()
}assertThat(string).all {
startsWith("L")
hasLength(3)
}
assertAll {
assertThat(false).isTrue()
assertThat(true).isFalse()
}