我使用TestNG进行单元测试。但是在Spring Test framework中,它们看起来都很相似。所以我相信你的测试如下
@Testpublic void testalertFilterView() throws Exception { this.mockMvc.perform(get("/getServeralertFilters/v2v2v2/"). .andExpect(status().isOk()) .andExpect(content().json("{'data':[{'useRegEx':'false','hosts':'v2v2v2'}]}")); }如果要检查json键和值,可以使用jsonpath
.andExpect(jsonPath("$.yourKeyValue",is("WhatYouExpect")));您可能会发现
content().json()无法解决,请添加
import staticorg.springframework.test.web.servlet.result.MockMvcResultMatchers.*;



