티스토리 뷰

Test/JUnit 5

[JUnit 5] 5. 태깅과 필터링

mandykr 2021. 12. 8. 15:07

1. @Tag

  - 그룹을 만들어  해당 태그가 붙은 테스트만 실행할 수 있다.

  - 다음과 같이 커스텀 태그로 만들어 사용해야 안전

    ("slow" 가 결국 문자열이기 때문에)

@Target(ElementType.METHOD)        
@Retention(RetentionPolicy.RUNTIME) 
@Test
@Tag("slow")
public @interface SlowTest {
}

class StudyTest {
    @SlowTest
    @DisplayName("스터디 만들기 2")
    void create_study_2() throws InterruptedException {
        System.out.println("스터디 만들기 2");
        Thread.sleep(1005L);
    }
}

 

2. IntelliJ에서 실행 방법

  - Edit Configurations 에서 Build and run 설정을 tag 로 변경, 원하는 태그의 속성 입력

 

 

 

 

 

출처

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

728x90