多重断言 (assertAll) - Kotest
Multiple assertions (assertAll) - Kotest
有什么方法可以在 DSL 风格的 Kotest 中检查多个断言 - 没有来自 JUnit 的 Assertions.assertAll 方法?
我可以这样写吗
firstValue shouldBe 1
and secondValue shouldBe 2
而不是
assertAll(
{ fistValue shouldBe 1 },
{ secondValue shouldBe 2 })
我通常用assertSoftly
来做。这可能正是您想要的。来自 documentation
assertSoftly {
foo shouldBe bar
foo should contain(baz)
}
或者作为参数使用
assertSoftly(foo) {
shouldNotEndWith("b")
length shouldBe 3
}
但是,您的语法同样有效。你真的不需要轻声断言。
firstValue shouldBe 1
secondValue shouldBe 2
将执行两个断言。如果第一个失败,测试会提前崩溃。使用 assertSoftly
,将检查两个断言。
有什么方法可以在 DSL 风格的 Kotest 中检查多个断言 - 没有来自 JUnit 的 Assertions.assertAll 方法?
我可以这样写吗
firstValue shouldBe 1
and secondValue shouldBe 2
而不是
assertAll(
{ fistValue shouldBe 1 },
{ secondValue shouldBe 2 })
我通常用assertSoftly
来做。这可能正是您想要的。来自 documentation
assertSoftly {
foo shouldBe bar
foo should contain(baz)
}
或者作为参数使用
assertSoftly(foo) {
shouldNotEndWith("b")
length shouldBe 3
}
但是,您的语法同样有效。你真的不需要轻声断言。
firstValue shouldBe 1
secondValue shouldBe 2
将执行两个断言。如果第一个失败,测试会提前崩溃。使用 assertSoftly
,将检查两个断言。