더북(TheBook)

다음 명령으로 작성한 테스트를 수행해 보자.

$ gradle test

메이븐을 사용한다면 다음 명령으로 테스트하면 된다.

$ mvn test

이 테스트 메서드는 Hamcrest 라이브러리의 Matchers, 스프링에서 제공하는 MockMvcRequest Builders, MockMvcResultMatchers의 정적 메서드 등 여러 정적 메서드를 사용했다. 이 메서드를 자세히 알아보기에 앞서 정적 임포트를 몇 개 추가하여 코드를 좀 더 간결하게 만들자.


import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.is;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;

신간 소식 구독하기
뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.