Java/Test

(Test) JUnit5 테스트 이름 표기하기

주누 2019. 12. 16. 20:59

@DisplayNameGeneration

  • Method와 Class 레퍼런스를 사용해서 테스트 이름을 표기하는 방법 설정.

  • 기본 구현체로 ReplaceUnderscores 제공

@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class)
class StudyTest {

ReplaceUnderscores : 언더바를 빈 공백 문자로 치환

 

좌 적용 전 우 적용 후

클래스에 적용하면 클래스 내의 모든 테스트 메서드에 적용

 

 

@DisplayName

  • 어떤 테스트인지 테스트 이름을 보다 쉽게 표현할 수 있는 방법을 제공하는 애노테이션.

  • @DisplayNameGeneration 보다 우선 순위가 높다.

@Test
@DisplayName("주누의 개인공부 시간")
void create_new_study() {
Study study = new Study();
assertNotNull(study);
System.out.println("create");
}

 

참고:

 

JUnit 5 User Guide

Although the JUnit Jupiter programming model and extension model will not support JUnit 4 features such as Rules and Runners natively, it is not expected that source code maintainers will need to update all of their existing tests, test extensions, and cus

junit.org