【发布时间】:2017-02-28 11:31:02
【问题描述】:
例如,
package com.spring.app;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
/**
* Handles requests for the application home page.
*/
@Controller
public class HomeController {
@RequestMapping(value = "/", method = RequestMethod.GET)
public String home(final Model model) {
model.addAttribute("msg", "SUCCESS");
return "hello";
}
}
我想使用 JUnit 从home() 测试model 的属性及其值。我可以将返回类型更改为ModelAndView 以使其成为可能,但我想使用String,因为它更简单。不过这不是必须的。
有没有在不改变home() 的返回类型的情况下检查model?还是没办法?
【问题讨论】:
标签: java spring unit-testing spring-mvc junit