Skip to content

Instantly share code, notes, and snippets.

@keesun
Last active December 23, 2015 23:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keesun/6711557 to your computer and use it in GitHub Desktop.
Save keesun/6711557 to your computer and use it in GitHub Desktop.
spock + spring mvc test: using mock
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())
}
}
Copy link

ghost commented Feb 10, 2014

1 * mockBookService.book(100) >> book는 어떻게 해석해야 하나요?
아래 문서를 봤는데도 정확히 이해가 되지 않네요.
http://groovy.codehaus.org/api/groovy/lang/Closure.html#rightShift%28groovy.lang.Closure%29

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment