【发布时间】:2014-04-06 14:11:00
【问题描述】:
我在我的 Spring MVC 控制器上做 junit -
@RequestMapping(value = "index", method = RequestMethod.GET)
public HashMap<String, String> handleRequest() {
HashMap<String, String> model = new HashMap<String, String>();
String name = "Hello World";
model.put("greeting", name);
return model;
}
下面是我对上述方法的junit -
public class ControllerTest {
private MockMvc mockMvc;
@Before
public void setup() throws Exception {
this.mockMvc = standaloneSetup(new Controller()).build();
}
@Test
public void test01_Index() {
try {
mockMvc.perform(get("/index")).andExpect(status().isOk());
} catch (Exception e) {
e.printStackTrace();
}
}
}
junit 以上工作正常..
但我的问题是我如何将handleRequest 的返回类型联合起来,它返回一个带有键和值对的HashMap。我如何验证它是否返回Hello World?有什么方法也可以做到吗?
【问题讨论】:
标签: java spring spring-mvc junit spring-mvc-test