日期:2014-05-19  浏览次数:20736 次

junit 怎么获得session值
本帖最后由 jimmykingl 于 2013-02-06 09:53:48 编辑
我用junit来测色web程序
这项目只是用struts来做的框架
请问junit怎么来往request放值
web代码如下

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {

// session取得
HttpSession session = request.getSession();


if (!LoginCheck.isLogin(session)) {
return (mapping.findForward(MAPPING_FINDFORWARD_TIMEOUT));
}

junit代码
public class ReferStrgSituationLogicTest extends MockStrutsTestCase{

@Test
public void testExecSearch() {
//ReferStrgSituationSearchForm from = null ;
//from.setClaimCd("1000000001");

HttpServletRequest request;

setRequestPathInfo("/ReferStrgSituationSearchServlet");
//setActionForm(from);
//addRequestParameter("searchInfo", from);
addRequestParameter("loginId", "admin00001");
addRequestParameter("brandCd", "TEST1");
addRequestParameter("pageFlg", "search");
actionPerform();
verifyForward("fail");
}

在junit怎么写往该代码?

------解决方案--------------------
以解决这问题了 哈哈 
this.getSession().setAttribute("brandCode", "TEST1");
from里有from的
ReferStrgSituationForm from  = new ReferStrgSituationForm();

from.getSearchInfo().setBillFrom("200001");
from.getSearchInfo().setBillTo("201912");
from.getSearchInfo().setClaimCd("1000000001");
from.setButtonNm("search");
// addRequestParameterMap("searchInfo", a);
// addRequestParameter("claimCd", "1000000001");
// addRequestParameter("billFrom", "200001");
// addRequestParameter("billTo", "201912");
setActionForm(from);