inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

[Practical Testing: 실용적인 테스트 가이드] 회고 4주차

lsmunt
0

출처 : Practical Testing: 실용적인 테스트 가이드

 

학습 내용 요약

섹션6 Spring & JPA 기반 테스트테스트케이스 세분화

Presentation Layer

/*
* readOnly = true : 읽기 전용
* CRUD에서 CUD 동작 X / only Read
* JPA : CUD 스냅샷 저장, 변경감지 X (성능 향상)
* 
* CQRS - Command(CUD) / Read Query 분리
* Read 빈도가 훨씬 많음
* Read에 의해 CUD가 영향 받아도 안되고 CUD에 의해 Read Query가 영향 받아서도 안됨
* */

 

Classicist vs Mockist

 

더 나은 테스트를 위한 구체적인 조언(섹션8)

한 문단에 한 주제

 

완벽하게 제어하기

 

테스트 환경의 독립성 보장

 

테스트 간 독립성 보장

 

한 눈에 들어오는 Test Fixture 구성

 

Test Fixture 클렌징

 

@ParameterizedTest

@ParameterizedTest
@CsvSource({
    "HANDMADE, false",
    "BOTTLE, true" ,
    "BAKERY, true" ,
})
@DisplayName("재고타입인지 테스트")
public void test2(ProductType productType, boolean expected) {
    // given


    // when
    boolean result = ProductType.containsStockType(productType);

    // then
    assertThat(result).isEqualTo(expected);
}
private static Stream<Arguments> ofProductTypes(){
    return Stream.of(
            Arguments.arguments(ProductType.HANDMADE, false),
            Arguments.arguments(ProductType.BOTTLE, true),
            Arguments.arguments(ProductType.BAKERY, true)
    );
}
@ParameterizedTest
@MethodSource("ofProductTypes")
@DisplayName("재고 관련 상품타입 확인")
void initializeGame(ProductType productType, boolean expected) {
    // given


    // when
    boolean result = ProductType.containsStockType(productType);

    // then
    assertThat(result).isEqualTo(expected);
}

 

@DynamicTest

 

테스트 수행도 비용이다. 환경 통합

 

class OrderControllerTest extends ControllerTestSupport {

    @Test
    ...
}

private 메서드 테스트는 어떻게?

 

테스트에만 필요한 메서드는 어떻게? (프로덕션 코드에 필요없는 메서드)

 

부록(섹션9)

학습 테스트

 

Spring REST Docs

 

Swagger

답변 0