Java/Java 학습

[JAVA] JUnit5 기본 테스트 어노테이션(@Test, BeforeAll, @BeforeEach, @AfterAll, @AfterEach, @Disabled)

HSY_mumu 2022. 4. 28. 13:09
728x90

1. @Test

@Test 어노테이션을 붙이면 테스트해야 할 Test메서드다.

JUnit5 기준으로 접근제한자가 Default 여도 된다. 

2. @BeforeAll

@beforeAll 어노테이션을 붙이면 해당 테스트 클래스를 초기화 할 때 1번만 수행되는 메서드.

static으로 선언해야 한다.

@BeforeAll
static void beforeAll() {
	System.out.println("@BeforeAll");
}

3. @BeforeEach

@beforeEach 어노테이션을 붙이면 각 테스트 메서드 실행 이전에 수행되는 메서드다.

@BeforeEach
void beforeEach() {
    System.out.println("@BeforeEach");
}

4. @AfterAll

@AfterAll 어노테이션을 붙이면해당 테스트 클래스 내 테스트 메서드를 모두 실행 시킨 후 1번만 수행되는 메서드.

static으로 선언해야 한다.

@AfterAll
static void afterAll() {
    System.out.println("@AfterAll");
}

5. @AfterEach

@AfterEach 어노테이션을 붙이면 각 테스트 메서드 실행 이후에 수행되는 메서드다.

@AfterEach
void afterEach() {
    System.out.println("@AfterEach");
}

6. @Disabled

@Disabled 어노테이션을 붙이면 무시해야할 Test메서드다.

@Disabled
@Test
void create3() {
    System.out.println("create3()");
}

 

[참고] https://gracelove91.tistory.com/107

 

[JUnit5] 기본 테스트 어노테이션(@Test, @BeforeAll, @BeforeEach, @AfterAll, @AfterEach, @Disabled)

본 포스팅은 백기선님의 "더 자바, 애플리케이션을 테스트하는 다양한 방법" 을 보고 정리한 글 입니다. 관심 있으신 분들은 https://www.inflearn.com/course/the-java-application-test 를 살펴보세요 개요 Juni..

gracelove91.tistory.com

 

728x90