Lifecycle annotations in nested classes behave differently than in top-level classes. While @BeforeEach and @AfterEach execute in a hierarchical manner, @BeforeAll and @AfterAll have specific requirements when used in nested classes.
Using @BeforeAll and @AfterAll in inner classes
Nested test classes can have @BeforeAll and @AfterAll methods (static) in modern JUnit 5 (version 5.5+). Originally static @BeforeAll/@AfterAll methods were not allowed because inner classes couldn't have static methods before Java 16. JUnit 5.5 introduced @TestInstance(Lifecycle.PER_CLASS) to enable non-static @BeforeAll/@AfterAll methods in inner classes. Since Java 16 allows static members in inner classes, nested test classes can now use static @BeforeAll/@AfterAll methods directly.