|
本帖最后由 lychbeyond 于 2010-11-23 10:16 编辑
//被测试struts2方法
public String execute() throws Exception {
loginParameter.setParameters(nickname, password);
LoginProcessor loginProcessor = new LoginProcessorByGeneralPasswordImpl();
String stringForAuthorization = loginProcessor.process(loginParameter);
Map request = null;
ActionContext ac = com.opensymphony.xwork2.ActionContext.getContext();
request = (Map) ac.get( "request");
request.put("userLoginContent", userLoginContent);
if (stringForAuthorization != "" && stringForAuthorization != null) { // 返回值非空
// 生成主功能画面
if ("007".equals(stringForAuthorization))
return ERROR;
if ("008".equals(stringForAuthorization)) {
}
return SUCCESS;
} else {
// 生成相关出错页面数据
return ERROR;
}
}
//测试方法
@Test
public void testexecute() throws Exception {
LoginEntry loginentry = new LoginEntry(); //初始化被测对象,可以放到setUp()里
loginEntry.setUsername(parameterUsername); //对Userkname属性进行参数赋值
loginEntry.setPassword(parameterPwd); //对Password属性进行参数赋值
assertEquals(parameterForward, loginEntry.execute()); //断言判定execute()方法返回值是否与预期值相等
}
出现的问题是:
assertEquals(parameterForward, loginEntry.execute()); 断言判断loginEntry.execute()方法返回值时
Map request = null;
ActionContext ac = com.opensymphony.xwork2.ActionContext.getContext();
request = (Map) ac.get( "request");
这里的request值是null,请问struts2的Action中Junit测试类testexecute() 怎么往loginEntry.execute()中传递request值? |
|