我是 JMock 的新手,正在尝试开发 Spring 控制器测试。这是我的测试方法:
@Test
public void testList() {
context.checking(new Expectations() {{
Student student = new Student(767001);
oneOf(studentService).getByNumber(767001); will(returnValue(student));
}});
ModelMap model = new ModelMap();
Student student = new Student(767001);
model.addAttribute("student", student);
CourseRightController instance = new CourseRightController();
request.setMethod("GET");
Assert.assertEquals(studentService.getByNumber(767001),model.get(student));
问题是我如何能够测试模型是否包含正确的对象和对象值?ModelMap 不如 ModelAndWiew 灵活。我无法访问模型属性,所以这里的最后一行代码不应该是这样。