사용자 도구

사이트 도구


java:spock

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

양쪽 이전 판 이전 판
다음 판
이전 판
다음 판 양쪽 다음 판
java:spock [2016/12/28 10:42]
kwon37xi
java:spock [2017/07/10 20:43]
kwon37xi [Dependencies]
줄 8: 줄 8:
 ===== Dependencies ===== ===== Dependencies =====
 <code> <code>
-testCompile group: 'org.spockframework', name: 'spock-core', version: '1.0-groovy-2.4'+testCompile group: 'org.spockframework', name: 'spock-core', version: '1.1-groovy-2.4'
 testCompile group: 'cglib', name: 'cglib-nodep', version: '3.2.4' // Class Mocking 할 때 필요. testCompile group: 'cglib', name: 'cglib-nodep', version: '3.2.4' // Class Mocking 할 때 필요.
 </code> </code>
줄 64: 줄 64:
 ===== Mock 선언이 작동하지 않을 때 ===== ===== Mock 선언이 작동하지 않을 때 =====
   * 대상 Class 혹은 Method가 ''**final**''로 선언돼 있으면 아무 오류없이 Mock 이 작동하지 않는다.   * 대상 Class 혹은 Method가 ''**final**''로 선언돼 있으면 아무 오류없이 Mock 이 작동하지 않는다.
 +
 +===== Spy =====
 +  * ''Spy()'' 사용시 스파이 대상 객체에 필드 인젝션이 안된다.
 +  * Spy객체 생성 후 Spring의 [[https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/test/util/ReflectionTestUtils.html|ReflectionTestUtils]]를 이용해서 따로 주입해주면 된다.
  
 ===== 오류 / Error ===== ===== 오류 / Error =====
   * [[https://github.com/spockframework/spock/issues/491|Spock and Slf4j combination causes compilation error]] : Spock에서 ''@groovy.util.logging.Slf4j'' 사용시에 ''Error:Groovyc: The current scope already contains a variable of the name $spock_valueRecorder'' 오류가 발생하는 경우가 있다. Logger 직접 선언할 것.   * [[https://github.com/spockframework/spock/issues/491|Spock and Slf4j combination causes compilation error]] : Spock에서 ''@groovy.util.logging.Slf4j'' 사용시에 ''Error:Groovyc: The current scope already contains a variable of the name $spock_valueRecorder'' 오류가 발생하는 경우가 있다. Logger 직접 선언할 것.
 +  * 1.0 버전에서 메소드가 여러개 override 돼 있을 경우 Type 지정이 명확하지 않으면 잘못된 메소드를 호출할 수도 있다.<code groovy>
 +// method 가 여러개로 override 돼 있을 경우 어떤 것이 호출될지 알 수 없음. 특히 return 도 서로 다를 때.
 +expect:
 +SomeClass.method(null) == null
 +
 +// 아래와 같이 파라미터와 리턴 타입을 모두 명시할 것.
 +when:
 +Result result = SomeClass.method(null as Request)
 +then:
 +result == null
 +</code>
  
 ===== 참조 ===== ===== 참조 =====
java/spock.txt · 마지막으로 수정됨: 2020/08/27 13:35 저자 kwon37xi