Spring 测试柱法弹簧

Spring 测试柱法弹簧,spring,mocking,spring-3,spring-test,Spring,Mocking,Spring 3,Spring Test,我想测试下面的控制器方法。有没有办法将配置文件对象添加到 模拟请求 MockHttpServletRequest request = new MockHttpServletRequest(); //request.add(myProfile); @RequestMapping(value = "/", method = RequestMethod.POST) public View postUser(ModelMap data, @Valid Profile profile) {} 您的概要

我想测试下面的控制器方法。有没有办法将配置文件对象添加到
模拟请求

MockHttpServletRequest request = new MockHttpServletRequest();
//request.add(myProfile);

@RequestMapping(value = "/", method = RequestMethod.POST)
public View postUser(ModelMap data, @Valid Profile profile) {}

您的概要文件对象应该根据作为请求参数提交的内容进行绑定,因此只需设置相关的请求参数,例如,如果您在概要文件中有一个字段作为名称,请设置该请求<代码>请求.添加参数(“名称”,“值”)


测试Spring MVC堆栈的一个非常好的方法是使用

,因为您可以看到我需要一个完整的概要文件项目。我的配置文件不能是字符串?是的,我的意思是您的配置文件将由Spring MVC堆栈根据您作为请求参数传入的内容创建。比如说,如果你的Profile类有id、name等字段,你需要传入id、name等,Spring MVC堆栈将这些请求参数绑定到Profile对象中(它将创建一个Profile对象,将id、name字段映射到Profile对象中的字段)。调用该方法时,我在Profile中放什么?