2
내 서비스에서 간단한 단위 테스트를 구현하려고합니다.봄 부팅 테스트로 오류 테스트
java.lang.IllegalStateException: Failed to load ApplicationContext
...
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerAdapter' defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter]: Factory method 'requestMappingHandlerAdapter' threw exception; nested exception is java.lang.NoClassDefFoundError: net/minidev/json/writer/JsonReaderI
...
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter]: Factory method 'requestMappingHandlerAdapter' threw exception; nested exception is java.lang.NoClassDefFoundError: net/minidev/json/writer/JsonReaderI
...
Caused by: java.lang.NoClassDefFoundError: net/minidev/json/writer/JsonReaderI
...
Caused by: java.lang.ClassNotFoundException: net.minidev.json.writer.JsonReaderI
...
내 코드의 문제점은 무엇입니까 : 테스트를 실행할 때, 난 항상 예외를 받고 있어요
@RunWith(SpringRunner.class)
@SpringBootTest
public class UserServiceTest {
@Mock
private UserRepository userRepoMock;
private UserService userService;
private List<User> users;
@Before
public void setUp() throws Exception {
userService = new UserService(userRepoMock);
User u1 = new User();
u1.setEmail("[email protected]");
User u2 = new User();
u2.setEmail("[email protected]");
users = Arrays.asList(u1, u2);
}
@Test
public void getAll() throws Exception {
when(userRepoMock.findAll()).thenReturn(users);
List<UserDTO> all = userService.getAll(new PageRequest(0, 20));
verify(userRepoMock).findAll();
}
}
,이 발췌 한 것입니다 : 내 테스트 클래스의 코드는 다음과 같다? spring-boot-starter-test
에 포함되지 않은 종속성을 포함시켜야합니까?
참고 저는 스프링 부트 v 1.5.1 및 스프링 데이터 MongoDB 리포지토리를 사용하고 있습니다.
응용 프로그램이 정상적으로 시작 되었습니까? 아니면 같은 오류가 발생합니까? 의존성에 Maven 또는 Gradle 사용? –
@WimDebrauwe Maven을 사용하고 있습니다. 예, 응용 프로그램이 올바르게 시작되고 있습니다 ... – davioooh
Maven'dependency : tree' 명령을 사용하여 필요한 종속성이 포함되어 있는지 확인할 수 있습니다. https://maven.apache.org/plugins/maven-dependency-plugin/tree-mojo.html Maven 또는 IDE에서 테스트를 실행하고 있습니까? IDE에서 최신 pom.xml 변경 사항을 가져 왔는지 확인 했습니까? –