Test classes and lifecycle

How a test class lives: @BeforeEach and @AfterEach give every test a fresh fixture and run in a fixed order, @BeforeAll and @AfterAll run once around the class and have to be static, and a failure there fails the whole class. The lessons then quiet a test with @Disabled, name it for the report with @DisplayName, and group tests in a @Nested class, which adds a branch to the report and keeps the outer @BeforeEach. The part ends with @TestInstance(PER_CLASS), where one instance serves every test and a @BeforeAll method no longer needs to be static.

011 Before and after every test @BeforeEach and @AfterEach, a fresh fixture, the order Open 012 Before and after the class @BeforeAll and @AfterAll, the static rule, a class-level failure Open 013 Disabled tests and display names @Disabled, @DisplayName, the skipped count Open 014 Nested test classes @Nested, the tree it adds, the outer @BeforeEach Open 015 One instance per class @TestInstance(PER_CLASS), a non-static @BeforeAll, shared state Open

Lessons