JUnit4 中有 ErrorCollector 规则,现在我们必须在迁移到 JUnit5 期间切换到扩展。此处描述了 ErrorCollector 的用法https://junit.org/junit4/javadoc/4.12/org/junit/rules/ErrorCollector.html JUnit5 中 是否有类似的扩展。我在 assert-j https://www.javadoc.io/doc/org.assertj/assertj-core/latest/org/assertj/core/api/junit/jupiter/SoftAssertionsExtension.html中找到了一个,但是是一样的JUnit 5 仍然支持作为扩展?
注意:我想在系统测试级别上使用它。所以我将有 Step 1 -> assertion -> Step 2-> assertion->... assertAll 在我看来是更糟糕的选择,因为我必须存储用于验证的值并在测试结束时断言它们,而不是在地方我从哪里得到这些值。
assertAll(() -> {{Some block of code getting variable2}
assertEquals({what we expect from variable1}, variable1, "variable1 is wrong")},
{Some block of code getting variable2}
assertEquals({what we expect from variable2}, variable2, "variable2 is wrong"),
{Some block of code getting variable3}
assertEquals({what we expect from variable3}, variable3, "variable3 is wrong"));
这种方法看起来不清晰,看起来比这里描述的更糟糕https://assertj.github.io/doc/#assertj-core-junit5-soft-assertions