【发布时间】:2013-05-29 08:38:10
【问题描述】:
我想为支持 bean 中的方法编写 jUnit 测试用例,但问题是 bean 的构造函数对“facesContext”方法有一些调用。通话是这样的
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().
put(
BEAN_NAME,
BEAN_OBJECT
);
如果我编写任何测试用例,它会抛出“NullPointerException”。我知道是因为 facesContext 没有初始化。
例如如果我有这样的方法
public String disableFields() throws ApplicationException
{
logger.info(empId);
logger.info(relationShip.getRelationshipName());
if(relationShip.getRelationshipName().equalsIgnoreCase("select"))
{
errorMessage="Please select relationship";
Utils.addMessage(errorMessage, FacesMessage.SEVERITY_ERROR);
return null;
}
showEmpName=true;// boolean value
return null;
}
如果可能的话,请给我推荐 jUnit 测试用例的代码......
请建议任何方法来为这些类型的方法编写 jUnits 测试用例....我使用的是 jsf 1.2..
提前致谢
【问题讨论】:
标签: unit-testing junit junit4 jsf-1.2