JUnit5 test에 사용할 수 있는 기본 annotation
- @Test
- @BeforeAll / @AfterAll : 모든 테스트 실행 전 혹은 실행 후 딱 한번씩만 실행됨
- @BeforeEach / @AfterEach : 각각 테스트들 마다 실행 전 / 실행 후에 매번 실행됨
- @Disabled : 여러개의 테스트 메소드중 제외 하고 싶은것에 붙여줌
package me.whiteship.inflearnthejavatest;
import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.*;
class StudyTest {
// junit5 부터 public 이 안붙어도됨
@Test
void create() throws Exception{
//given
Study study = new Study();
assertNotNull(study);
System.out.println("create");
}
@Test
@Disabled
public void create1() throws Exception{
//given
System.out.println("create1");
//when
//then
}
// 모든 테스트들이 실행하기 전에 딱 한번만 실행 됨
// 이 메소드는 꼭 static을 사용해야하고 return type이 없어야함
@BeforeAll
static void beforeAll(){
System.out.println("before All");
}
// 모든 테스트들이 실행한 후에 딱 한번만 실행 됨
@AfterAll
static void afterAll(){
System.out.println("After All");
}
// 테스트들이 시작하기 전에 매번 이걸 한번씩 호출됨
// static이 아니여도됨
@BeforeEach
void beforeEach(){
System.out.println("before Each");
}
// 테스트들이 시작하기 후에 매번 이걸 한번씩 호출됨
@AfterEach
void afterEach(){
System.out.println("after each");
}
}
'JAVA' 카테고리의 다른 글
Mockito (0) | 2022.12.14 |
---|---|
JUnit5 Assertions (0) | 2022.12.14 |
Homebrew mysql 설치 (0) | 2022.12.07 |
JWT (2) | 2022.11.30 |
spring boot 프로젝트 생성과 사용 이유 (0) | 2022.10.31 |