사용자 도구

사이트 도구


java:spock

차이

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

차이 보기로 링크

양쪽 이전 판 이전 판
다음 판
이전 판
다음 판 양쪽 다음 판
java:spock [2018/07/12 08:13]
kwon37xi [Mock Argument Capture]
java:spock [2018/09/06 10:25]
kwon37xi
줄 5: 줄 5:
   * [[http://meetspock.appspot.com/|Spock Web Console]]   * [[http://meetspock.appspot.com/|Spock Web Console]]
   * [[https://leanpub.com/spockframeworknotebook|Spocklight notebook]]   * [[https://leanpub.com/spockframeworknotebook|Spocklight notebook]]
 +  * [[https://solidsoft.wordpress.com/2018/09/03/spock-1-2-hassle-free-spring-beans-mocking-in-integration-tests/|Spock 1.2 – hassle-free Spring beans mocking in integration tests | Solid Soft]]
  
 ===== Dependencies ===== ===== Dependencies =====
줄 62: 줄 63:
 </code> </code>
  
-===== void method Mock - throw exception =====+  * void 메도드의 경우 아래 참조. 
 +===== void method Mock - 인자 값 조정 혹은 throw exception =====
   * [[http://farenda.com/spock/spock-framework-mock-throw-exception/|Spock Framework Mock throw exception - Java Programming Tutorials]]   * [[http://farenda.com/spock/spock-framework-mock-throw-exception/|Spock Framework Mock throw exception - Java Programming Tutorials]]
  
 <code groovy> <code groovy>
 +    // an interface with two methods: exists(user), add(user)
 +    def userService = Mock(UserService)
 + 
 +    // a controller to test, that will use mock of the service:
 +    def controller = new UserController(userService)
 + 
 +    def 'should throw exception for invalid username'() {
 +        given:
 +        def username = 'Joffrey Baratheon'
 +        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
 +    }
 </code> </code>
  
java/spock.txt · 마지막으로 수정됨: 2020/08/27 13:35 저자 kwon37xi