문서의 선택한 두 판 사이의 차이를 보여줍니다.
양쪽 이전 판 이전 판 다음 판 | 이전 판 다음 판 양쪽 다음 판 | ||
java:spock [2017/07/05 17:48] kwon37xi |
java:spock [2018/09/06 10:25] kwon37xi |
||
---|---|---|---|
줄 5: | 줄 5: | ||
* [[http:// | * [[http:// | ||
* [[https:// | * [[https:// | ||
+ | * [[https:// | ||
===== Dependencies ===== | ===== Dependencies ===== | ||
< | < | ||
- | testCompile group: ' | + | testCompile group: ' |
testCompile group: ' | testCompile group: ' | ||
</ | </ | ||
줄 60: | 줄 61: | ||
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 | ||
+ | } | ||
</ | </ | ||