我正在尝试更改以下 Spring Test Framework 以测试以下 json 返回:
{"user":"John ","name":"JohnSmith"}
这是我的测试代码,我只是不知道如何更改它以检查 JSON 和 JSON 中的值。如果有人能告诉我要改变什么,那就太好了..谢谢
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {WebMVCConfig.class})
@WebAppConfiguration
public class TestHelloWorldWeb
{
@Autowired
private WebApplicationContext wac;
private MockMvc mockMvc;
@Before
public void setup()
{
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
}
@Test
public void getFoo() throws Exception
{
this.mockMvc.perform(get("/ask")
.accept(MediaType.TEXT_HTML))
.andExpect(status().isOk())
.andExpect(view().name("helloworld"))
.andExpect(MockMvcResultMatchers.model().attribute("user", "JohnSmith"))
;
}
}