Controller Test를 실행하니 해당 에러가 발생하였다.
java.lang.IllegalStateException: Failed to load ApplicationContext
🧐 @WebMvcTest 애너테이션을 사용할 경우, @SpringBootTest를 사용하는 것과 달리 테스트 진행에 필요한 ApplicationContext를 하나하나 설정해줘야 하는데 그걸 제대로 하지 않아 나타나는 것 같았다.
API 계층 슬라이스테스트
에러 메세지를 자세히 보면 하단의 문구를 확인할 수 있다.
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'answerController' defined in file [C:\Users\Hyeri\Desktop\preproject\seb41_pre_030\Server\build\classes\java\main\Be_30\Project\answer\controller\AnswerController.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'Be_30.Project.answer.mapper.AnswerMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
대충 Controller에서 DI받은 mapper가 제대로 설정되지 않아 생긴 문제같군..
😮 헉쓰바리~ Mapper에 @Autowired를 지우고 @MockBean을 추가하니 해당 에러는 말끔하게 사라졌다.