setActionForm()方法会调用ActionForm里的reset()方法清掉你传入actionForm中的测试数据。
如:
EmailResetPsdForm form = new EmailResetPsdForm();
form.setUserName("ppig");
setActionForm(form);
在这里,测试数据userName="ppig"不会被传入使用这个form bean的action中。
应该使用替代的方法来传递测试数据:
addRequestParameter("userName", "ppig");
下面是strutstestcase里的文档对setActionForm方法的说明。
/*
* setActionForm
* public void setActionForm(ActionForm form)Sets an ActionForm instance to be used in this
* test. The given ActionForm instance will be stored in the scope specified in the Struts
* configuration file (ie: request or session). Note that while this ActionForm instance
* is passed to the test, Struts will still control how it is used. In particular, it
* will call the ActionForm.reset() method, so if you override this method in your
* ActionForm subclass, you could potentially reset attributes in the form passed
* through this method.
*
* Parameters:
* form - the ActionForm instance to be used in this test.
*
*/