Nested tests give the test writer more capabilities to express the relationship and order in a group of tests. JUnit 5 makes it effortless to nest test classes. We simply need to annotate inner classes with @Nested and all test methods in there will be executed as well, going from the regular tests (defined in the top-level class) to the tests defined in each of the inner classes.
The first thing we need to take into account is that only non-static nested classes (that is inner classes) can serve as @Nested tests. Nesting can be arbitrarily deep, and the setup and tear down for each test (that is, @BeforeEach and @AfterEach methods) are inherited in the nested tests. Nevertheless, inner classes cannot define the @BeforeAll and @AfterAll methods, due to the fact that Java does not allow static members in inner classes. However, this restriction can be avoided...