728x90
- SpringBoot 2.2 이상부터는 SpringBootStarter가 제공하는 JUnit 버전이 변경되었다(4 -> 5)
- JUnit5부터는 public 제약이 사라졌다
- 기본 애노테이션
- @Test
- @BeforeAll / @AfterAll
- private X, default O, return Type 존재 X
- 테스트를 실행할 때 딱 1번만 실행된다.
- @BeforeEach / @AfterEach
- 테스트가 실행될 때마다 실행된다.
- @Disabled
- 실행하고 싶은 Test가 존재할 경우 실행한다.
-
class StudyTest { @Test void create(){ //JUNIT5 부터는 public 제약이 사라졋다 Study study = new Study(); assertNotNull(study); System.out.println("create"); } @Test @Disabled //실행하고 싶지 않은 테스트에 표기한다. public void create1(){ System.out.println("create1"); } @BeforeAll //private X, default O, return Type 존재 X static void beforeAll(){ //테스트를 실행할때 딱 1번만 실행된다. System.out.println("before all"); } @AfterAll static void afterAll(){ System.out.println("after all"); } @BeforeEach void beforeEach(){ //테스트를 실행 할 떄마다 실행된다. System.out.println("BeforeEach each"); } @AfterEach void afterEach(){ System.out.println("After each"); } }
728x90
'더 자바, 애플리케이션을 테스트하는 다양한 방법' 카테고리의 다른 글
| Ch01. JUnit5 - JUnit5 태깅과 필터링 (0) | 2022.01.04 |
|---|---|
| Ch01. JUnit5 - JUnit 5 조건에 따라 테스트 실행하기 (0) | 2022.01.03 |
| Ch01. JUnit5 - JUnit5 Assertion (0) | 2022.01.03 |
| Ch01. JUnit5 - JUnit5 테스트 이름 표시하기 (0) | 2022.01.03 |
| Ch01. JUnit5 - JUnit 5 소개 (0) | 2022.01.03 |