From the course: Complete Guide To Java Testing with JUnit 5 & Mockito

Unlock the full course today

Join today to access over 25,200 courses taught by industry experts.

AssertAll

AssertAll

- [Instructor] assertAll is a function that allows developers to group multiple assertions and run them simultaneously. This means you can execute several assertions in one go and see all the assertion failures at once, rather than stopping at the first failure encountered. This approach can be particularly useful when testing complex objects or systems where multiple conditions need to be validated at the same time. Let's take a look at an example. Here, we have a Person class. It is several fields, name, age, email, address. We'll want to validate the correctness of all these fields at the same time rather than one by one. Let's create a test for this and we'll use assertAll to group our assertions. We'll create a test and we'll call it personFields. Then we'll create a new person. Then we'll list out all the things we want to assert. We'll assert the name is John Doe. We'll also assert the age, email address, and address. Let's group these assertions with assertAll. We'll write…

Contents