参考サイト

http://etc9.hatenablog.com/entry/2015/04/12/195504 https://koji-k.github.io/groovy-tutorial/unit-test/index.html

記載方法

Responseを出すprintln(res.andReturn().response.contentAsString)
[]list
[:]map
[] as Setset

Controllerのテスト

   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: 2017, today: 3, yesterday: 2

トップ   編集 凍結 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2022-10-14 (金) 13:16:52