문서의 선택한 두 판 사이의 차이를 보여줍니다.
양쪽 이전 판 이전 판 다음 판 | 이전 판 다음 판 양쪽 다음 판 | ||
java:spock [2017/07/05 17:48] kwon37xi |
java:spock [2020/06/26 14:33] kwon37xi [Spock 1.3 & groovy 2.5 문제점] |
||
---|---|---|---|
줄 2: | 줄 2: | ||
* [[https:// | * [[https:// | ||
* Test 코드가 설계 명세서 역할을 할 수 있을 정도로 가독성 높은 테스트를 짤 수 있다. | * Test 코드가 설계 명세서 역할을 할 수 있을 정도로 가독성 높은 테스트를 짤 수 있다. | ||
+ | * [[java: | ||
* [[http:// | * [[http:// | ||
* [[http:// | * [[http:// | ||
* [[https:// | * [[https:// | ||
+ | * [[https:// | ||
===== Dependencies ===== | ===== Dependencies ===== | ||
< | < | ||
- | testCompile group: ' | + | testCompile group: ' |
testCompile group: ' | testCompile group: ' | ||
</ | </ | ||
줄 60: | 줄 62: | ||
capturedEvent.newModel == newModel | capturedEvent.newModel == newModel | ||
capturedEvent.oldModel == oldModel | capturedEvent.oldModel == oldModel | ||
+ | </ | ||
+ | |||
+ | * void 메도드의 경우 아래 참조. | ||
+ | |||
+ | ===== void method Mock - 인자 값 조정 혹은 throw exception ===== | ||
+ | * [[http:// | ||
+ | |||
+ | <code groovy> | ||
+ | // an interface with two methods: exists(user), | ||
+ | def userService = Mock(UserService) | ||
+ | |||
+ | // a controller to test, that will use mock of the service: | ||
+ | def controller = new UserController(userService) | ||
+ | |||
+ | def ' | ||
+ | given: | ||
+ | def username = ' | ||
+ | userService.exists(_ as User) >> false | ||
+ | userService.add(_ as User) >> { User user -> | ||
+ | throw new IllegalArgumentException(user.name) | ||
+ | } | ||
+ | |||
+ | when: | ||
+ | controller.addUser(username) | ||
+ | |||
+ | then: | ||
+ | def e = thrown(IllegalArgumentException) | ||
+ | e.message == username | ||
+ | } | ||
</ | </ | ||
===== Mock 선언이 작동하지 않을 때 ===== | ===== Mock 선언이 작동하지 않을 때 ===== | ||
* 대상 Class 혹은 Method가 '' | * 대상 Class 혹은 Method가 '' | ||
+ | |||
+ | ===== 기타 Mock ===== | ||
+ | <code groovy> | ||
+ | 0 * _ // 이 위 이후로는 어떠한 모의객체 호출 행위도 없어야 한다. | ||
+ | </ | ||
===== Spy ===== | ===== Spy ===== | ||
줄 82: | 줄 118: | ||
result == null | result == null | ||
</ | </ | ||
+ | |||
+ | ===== Spock 1.3 & groovy 2.5 문제점 ===== | ||
+ | * groovy 2.4 로는 발생하지 않지만 2.5로 가면 '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * spock 1.3 에서 Argument capture 방식 변경됨. [[https:// | ||
+ | * [[http:// | ||
+ | |||
===== 참조 ===== | ===== 참조 ===== |