assertj: check() method from AbstractSoftAssertions fails on first assertion
Hello,
I have an issue related to assertj-core 3.15.0.
When I’m using check() method from AbstractSoftAssertions, I get only first fail from assertion passed to this method.
For example, if I have following code:
String text = "assertJ-Core";
softly.check(() -> assertThat(text).startsWith("core").isEmpty());
only first assertion error will be caught (in this case “startsWith” assertion).
I don’t know if it’s intended behaviour, but in my opinion it clashes with soft assertions purpose and chainability of assertions provided by AssertJ.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 17 (8 by maintainers)
Commits related to this issue
- Add two ways to react to collected assertion error. Fixes #1800 — committed to rpolton/assertj-core by joel-costigliola 4 years ago
- Add two ways to react to collected assertion error. Fixes #1800 — committed to assertj/assertj by joel-costigliola 4 years ago
Hello @joel-costigliola
I’m really happy how it turned out, beacuse this will allow to do exactly what I want and many more, I suppose 😃
Big thanks!
assertj-core-3.16-test.zip In the archive there are all classes needed to check it (assertion in the test is just dummy code, so it will always fail).
I’ll let you know when I have a draft to get some feedback
Hello @tifhorn, this is expected behavior.
The purpose of
check()
is to allow you to use the standard or your custom assertions.Each assertion should be described separately. You can go to
SoftAssertions
and read its documentation for more examples. Anyway, in your case you can use something like this:assertSoftly
is used to avoid having to call assertAll manually