-JUnitより見やすいと評判
#contents
*参考サイト [#udfafaac]
http://etc9.hatenablog.com/entry/2015/04/12/195504
https://koji-k.github.io/groovy-tutorial/unit-test/index.html
**記載方法 [#me854f99]
|Responseを出す|println(res.andReturn().response.contentAsString)|
|[]|list|
|[:]|map|
|[] as Set| set|
*Controllerのテスト [#xfdf3282]
def setup() {
mvc = MockMvcBuilders.standaloneSetup(controller)
.build()
}
def '入力エラー_未入力'() {
setup:
def params = new HashMap()
def content = new JsonBuilder()
content.call(params)
MockHttpServletRequestBuilder req = post('/hogehoge')
.accept(MediaType.APPLICATION_JSON_VALUE)
.contentType(MediaType.APPLICATION_JSON_VALUE)
.content(content.toString())
expect:
def res = mvc.perform(req)
res.andExpect(status().isBadRequest())
}
#counter