我是新來JMock的,試圖建立一個春天控制器測試。這裏是我的測試方法:測試ModelMap春與JMock的
@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那樣靈活。我無法訪問模型屬性,因此這裏的最後一行代碼不是應該如何使用的。
模型如何實際被itialized? – mjgirl
在超類中的'模型=新ExtendedModelMap()的方法@Before;'我把它添加到例如 – blank