티스토리 뷰

1. 기본 어노테이션

1) @BeforeAll, @AfterAll

   - 테스트 전체의 시작과 끝에 한번만 실행

   - static 메소드로 만들어야 함

2) @BeforeEach, @AfterEach

   - 테스트 각각의 시작과 끝에 한번씩 실행

3) @Disabled

   - 해당 테스트를 제외시킬 때 사용

class StudyTest {
    @Test
    void create1() {
        Study study = new Study();
        assertNotNull(study);
        System.out.println("create1");
    }

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

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

    @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");
    }
}

>> 실행 결과

beforeAll
beforeEach
create1
afterEach
beforeEach
create2
afterEach
afterAll

 

 

 

출처

https://www.inflearn.com/course/the-java-application-test 더 자바, 애플리케이션을 테스트하는 다양한 방법(백기선)

728x90