Multiple assertions (assertAll) - Kotest
Asked Answered
D

1

5

Is any way to check multiple assertions in Kotest in DSL style - without Assertions.assertAll method from JUnit?

Can I write something like

firstValue shouldBe 1
and secondValue shouldBe 2

Instead of

assertAll(
    { fistValue shouldBe 1 },
    { secondValue shouldBe 2 })
Dissymmetry answered 13/7, 2020 at 16:36 Comment(0)
C
6

I usually do it with assertSoftly. It probably is exactly what you want. From the documentation

assertSoftly {
  foo shouldBe bar
  foo should contain(baz)
}

Or using it as a parameter

assertSoftly(foo) {
    shouldNotEndWith("b")
    length shouldBe 3
}

However, your syntax works just as fine. You don't really need to assert softly.

firstValue shouldBe 1
secondValue shouldBe 2

will execute both assertions. If the first one fails the test crashes early. With assertSoftly, both assertions will be checked.

Choric answered 13/7, 2020 at 17:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.