What if you could find all your test mistakes in one go instead of fixing them one by one?
Why assertAll for grouped assertions in JUnit? - Purpose & Use Cases
Imagine testing a webpage where you need to check multiple things like the title, header, and footer text one by one manually.
You write separate tests and run them one after another, stopping at the first failure.
This manual way is slow because you fix one problem, then run tests again to find the next issue.
You miss seeing all problems at once, which wastes time and causes frustration.
Using assertAll lets you group many checks together.
It runs all assertions and shows every failure in one go, so you know all issues immediately.
assertEquals("Title", page.getTitle()); assertEquals("Header", page.getHeader()); assertEquals("Footer", page.getFooter());
assertAll( () -> assertEquals("Title", page.getTitle()), () -> assertEquals("Header", page.getHeader()), () -> assertEquals("Footer", page.getFooter()) );
You can quickly see all test failures together, making debugging faster and more efficient.
When testing a user profile page, you want to verify name, email, and phone number all at once.
With assertAll, you get all missing or wrong fields reported in one test run.
Manual checks stop at first failure, hiding other issues.
assertAll runs all assertions and reports all failures together.
This saves time and helps fix problems faster.