public interface ResultActionsMockMvcResultMatchers および MockMvcResultHandlers の静的ファクトリメソッドを参照してください。
| 修飾子と型 | メソッドと説明 |
|---|---|
ResultActions | andDo(ResultHandler handler) 一般的なアクションを実行します。 |
ResultActions | andExpect(ResultMatcher matcher) 期待を実行します。 |
MvcResult | andReturn() 結果に直接アクセスするために、実行されたリクエストの結果を返します。 |
ResultActions andExpect(ResultMatcher matcher) throws ExceptionSE
static imports: MockMvcRequestBuilders.*, MockMvcResultMatchers.*
mockMvc.perform(get("/person/1"))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$.person.name").value("Jason"));
または、すべてのマッチャーを可変引数として提供します。
static imports: MockMvcRequestBuilders.*, MockMvcResultMatchers.*, ResultMatcher.matchAll
mockMvc.perform(post("/form"))
.andExpect(matchAll(
status().isOk(),
redirectedUrl("/person/1"),
model().size(1),
model().attributeExists("person"),
flash().attributeCount(1),
flash().attribute("message", "success!"))
);
ExceptionSEResultActions andDo(ResultHandler handler) throws ExceptionSE
static imports: MockMvcRequestBuilders.*, MockMvcResultMatchers.*
mockMvc.perform(get("/form")).andDo(print());
ExceptionSEMvcResult andReturn()