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/6711547 to your computer and use it in GitHub Desktop.
Save keesun/6711547 to your computer and use it in GitHub Desktop.
simple spock + spring mvc test
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.content
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
/**
* @author Keesun Baik
*/
class SampleControllerTest extends Specification {
MockMvc mockMvc;
def setup() {
mockMvc = MockMvcBuilders.standaloneSetup(new SampleController()).build()
}
def "스팍과 스프링 MVC 테스트 연동 테스트"() {
when:
def response = mockMvc.perform(get("/hello"))
then:
response.andExpect(status().isOk())
.andExpect(content().string("spock"))
response.andReturn().response.contentAsString == "hello spock"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment