Home > Back-end >  Springtest MockMvc judge return json value package (high)
Springtest MockMvc judge return json value package (high)

Time:10-19

I use springtest MockMvc test Controller class, following a piece of code:
String responseString=mock. Perform (MockMvcRequestBuilders. Post ("/user/login/noauth ")
CharacterEncoding (" utf-8 ")
ContentType (MediaType. APPLICATION_JSON). The content (requestJson. GetBytes ()))
AndExpect (MockMvcResultMatchers. The status (). IsOk ())
AndExpect (jsonPath (" $. RepMsg ", is (" success ")))
AndExpect (jsonPath (" $. RepCode ", is (" 0000 ")))
AndReturn (). The method getResponse (). GetContentAsString ();
JsonPath (" $. RepMsg ", is (" success "), the method is don't know which bag from the import, please expert advice,

CodePudding user response:

JsonPath and is are methods to define your own???????

CodePudding user response:

JsonPath and is not their own definition,

CodePudding user response:

AndExpect (jsonPath (" $. RepMsg ", is (" success ")))
AndExpect (jsonPath (" $. RepCode ", is (" 0000 ")))/can not

CodePudding user response:

The import static org. Springframework. Test. Web. Servlet. Result. MockMvcResultMatchers. JsonPath;

CodePudding user response:

The import static org. Hamcrest. CoreMatchers. Is;
  • Related