How to test that method has added redirectAttributes ?(by MockMvc)

后端 未结 1 1203
轻奢々
轻奢々 2021-01-17 21:02

I have wrote this method:

@RequestMapping(value=\"/someURL\", method=GET)
public String myMethod(RedirectAttributes redirectAttributes)
{
   redirectAttribut         


        
相关标签:
1条回答
  • 2021-01-17 21:49

    You can use MockMvcResultMatchers#flash() which returns a FlashAttributeResultMatchers object which has an attribute() method.

    mockMvc.perform(MockMvcRequestBuilders.get("/someURL"))
                .andExpect(MockMvcResultMatchers.model().attribute("rd", "rdValue"))
                .andExpect(MockMvcResultMatchers.flash().attribute("fa", someValueThatEqualsFaValue));
    

    Note that "rd" will be a Model attribute, not a flash attribute.

    0 讨论(0)
提交回复
热议问题