Spy

Spock을 이용하여 MockBean을 생성하였는데, 정의한 행위대로 동작하지 않는 이슈를 발견했다. 간단히 작성해보자면 아래와 비스무리한 코드였다. @Autowired private SimpleMapper simpleMapper; ... @TestConfiguration def setup() { def factory = new DetachedMockFactory() @Bean SimpleMapper simpleMapper() { return factory.Mock(SimpleMapper) } } def "test"() { given: simpleService.selectSomething(_) >> "SUCCESS" expect: "SUCCESS" == simpleService.selectSomethin..
목(Mock)객체를 스터빙(stubbing) 할때 아래와 같이 사용한다. when(..).thenReturn(..) List mockedList = mock(List.class); when(mockedList.get(0)).thenReturn("foo"); 스파이(Spy)객체도 위와같이 스터빙(stubbing)을 할 것같지만, 위와 같이 사용하면 안된다. 그 이유는 스파이 객체는 리얼 객체이기 때문이다. 스파이(Spy) 객체에서는 when(object)을 사용하면, 실제 객체가 호출되버린다. 따라서 스파이(Spy)객체에서는 when을 사용하지 않고 doReturn(..).when(..)을 사용해야한다. Sometimes it's impossible or impractical to use when(Obje..
깡냉쓰
'Spy' 태그의 글 목록