JUnit 5 @BeforeAll annotation denotes a method that it is a lifecycle method. @BeforeAll is the replacement of @BeforeClass annotation in JUnit 4.

1. @BeforeAll Annotation

@BoforeAll is used show that  annotated method should be executed before all the @Test@RepeatedTest@ParameterizedTest, and @TestFactory methods in the current class.

By default, the test methods will be executed in the same thread as @BeforeAll annotated method.

  • @BeforeAll annotated method MUST be a static method in the test class.
public static void init(){
	System.out.println("BeforeAll init() method called");

Recommended posts :

Mockito Annotations