Last active
December 23, 2015 23:39
-
-
Save keesun/6711557 to your computer and use it in GitHub Desktop.
spock + spring mvc test: using mock
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package whiteship | |
import org.springframework.test.web.servlet.MockMvc | |
import org.springframework.test.web.servlet.setup.MockMvcBuilders | |
import spock.lang.Specification | |
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get | |
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status | |
/** | |
* @author Keesun Baik | |
*/ | |
class BookControllerTest extends Specification { | |
MockMvc mockMvc; | |
BookService mockBookService; | |
def setup() { | |
def controller = new BookController() | |
mockBookService = Mock(BookService.class) | |
controller.service = mockBookService; | |
mockMvc = MockMvcBuilders.standaloneSetup(controller).build(); | |
} | |
def "서비스는 가짜 객체로 바꾸고 테스트"() { | |
given: | |
def book = "book100" | |
when: | |
def response = mockMvc.perform(get("/book/100")) | |
then: | |
1 * mockBookService.book(100) >> book | |
response.andExpect(status().isOk()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
1 * mockBookService.book(100) >> book는 어떻게 해석해야 하나요?
아래 문서를 봤는데도 정확히 이해가 되지 않네요.
http://groovy.codehaus.org/api/groovy/lang/Closure.html#rightShift%28groovy.lang.Closure%29