
spring boot에서 프로젝트를 생성 했다.
JUnit5은 2.2+ 버전의 스프링 부트 프로젝트를 만든다면 기본으로 JUnit 5 의존성 추가되어있다.
package com.test;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
public class StudyTest {
@Test
void create() {
Study study = new Study();
assertNotNull(study);
System.out.println("@Test");
}
@Test
@Disabled
void create1() {
Study study = new Study();
assertNotNull(study);
System.out.println("@Disabled");
}
@BeforeAll
static void beforeAll() {
System.out.println("@BeforeAll");
}
@AfterAll
static void afterAll() {
System.out.println("@AfterAll");
}
@BeforeEach
void beforeEach() {
System.out.println("@BeforeEach");
}
@AfterEach
void afterEach() {
System.out.println("@AfterEach");
}
}

@Test
void create() {
Study study = new Study();
assertNotNull(study);
System.out.println("@Test");
}
@Test가 붙여져 있는 메소드들은 테스트 대상임을 의미한다.
@Test가 붙여져 있는 메소드들을 실행 하기 전에 먼저 실행 된다.
이 메소드들은 static void를 사용 해야한다.
@Test가 붙여져 있는 메소드들을 모두 실행되면 나중에 실행 된다.
이 메소드들은 static void를 사용 해야한다.
@Test가 붙여져 있는 메소드들이 실행하기 전 마다 먼저 실행된다.
@Test가 붙여져 있는 메소드들이 실행후 종료될때 마다 실행된다.
@Disabled가 붙여져있는 메소드는 실행되지 않는다.