luke0408 / Practical_Spring_Testing

[인프런] Practical Testing: 실용적인 테스트 가이드 - 실습
0 stars 0 forks source link

Section 04 - 테스트는 [ ]다. #3

Open luke0408 opened 1 year ago

luke0408 commented 1 year ago
luke0408 commented 10 months ago

테스트는 "문서"다.

[ 왜 문서인가? ]

luke0408 commented 10 months ago

DisplayName을 섬세하게

DisplayName: Junit 5 부터 나온 어노테이션으로 Test의 이름을 지어줄 수 있음

1. 명사의 나열보다 문장으로

A이면 B이다. 또는 A이면 B가 아니고 C다.

2. 테스트 행위에 대한 결과까지 기술하기

3. 도메인 용어를 사용하기

메서드 자체의 관점보다 도메인 정책 관점으로

luke0408 commented 10 months ago

BDD 스타일로 작성하기

BDD: Behavior Driven Development

BDD란?

Given / When / Then

예시

@Test
@DisplayName("주문 목록에 담긴 상품들의 총 금액을 계산 할 수 있다.")
void calculateTotalPrice() {
    // given
    CafeKiosk cafeKiosk = new CafeKiosk();
    Americano americano = new Americano();
    Latte latte = new Latte();

    cafeKiosk.add(americano);
    cafeKiosk.add(latte);

    // when
    int totalPrice = cafeKiosk.calculateTotalPrice();

    // then
    assertThat(totalPrice).isEqualTo(8500);
}
luke0408 commented 10 months ago

JUnit vs. Spock

To-Do: 둘이 비교해보기