inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

[인프런워밍업클럽 3기 BE] 2주차 발자국

pej4303
0

1. 강의

강의 진도 : 섹션3 ~ 섹션4

1.1 학습내용

@Test
fun getIntroductions() {
    /**
     * given : 조건 설정
     */
    val list = mutableListOf<Introduction>()

    // DATA_SIZE 만큼 반복하면서 isActive는 i가 짝수일 경우 true 홀수일 경우 false로 설정한다.
    for (i in 1..DATA_SIZE) {
        val introduction = Introduction(content = "${i}", isActive = i%2 == 0)
        list.add(introduction)
    }

    /**
     * when : 동작 설정 및 실행
     */
    // isActive가 true인 항목들만 필터링하여 activeList를 만든다.
    val activeList = list.filter { item -> item.isActive }

    // presentationRepository.getActiveIntroductions()가 호출되었을 때 반환할 값으로 설정한다.
    // when이 코틀린에서 예약어여서 `when`이 된거
    Mockito.`when`(presentationRepository.getActiveIntroductions())
        .thenReturn(activeList)

    // 실제로 테스트할 대상인 presentationService.getIntroductions() 메서드를 호출하고 그 결과를 introductionDTO에 저장한다.
    val introductionDTO = presentationService.getIntroductions()

    /**
     * then : 결과 검증
     */
    // introductionDTO의 크기가 DATA_SIZE / 2인지 확인한다.
    assertThat(introductionDTO).hasSize(DATA_SIZE / 2)
    // 각 introduction의 content 값이 짝수인지 확인한다.
    // content는 문자열이지만 이를 toInt()로 변환하여 짝수인지 검증한다.
    for (introduction in introductionDTO) {
        assertThat(introduction.content.toInt()).isEven()
    }
}

1.2 느낀 점

이번 주는 바쁜 일정 속에서도 커리큘럼에 맞춰 강의를 모두 수강할 수 있어 뿌듯하다.
특히 DB, 서비스, 컨트롤러별로 테스트 코드를 작성해 보면서 중요성을 다시 한번 느꼈고 실무에서도 적용을 해봐야겠다고 생각했다.


2. 미션

2.1. 테이블 설계하기

image

2.2. REST API 설계하기

2.3. 느낀 점

짧은 기한 내에 미션을 하는 게 힘들긴 했지만 스터디를 계기로 간단하게나마 테이블과 API 설계를 해보게 되어서 재밌었다.

출처

백엔드 발자국 인프런워밍업클럽

답변 0