|
我学做个例子:struts2.2.1+spring2.5+hibernate3.0+junit4
其中stuts.xml文件如下:
<constant name="struts.objectFactory" value="spring" />
<!-- Add packages here -->
<package name="default" namespace="/ut/regnlogin" extends="struts-default">
<action name="activateUserByEmail" class="activateUserByEmailBean">
<result>/ut/regnlogin/success.jsp</result>
<result name="error">/ut/regnlogin/error.jsp</result>
</action>
测试类如下:
public class ActivateUserByEmailTest extends StrutsTestCase{
@Test
public void testExecute() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setParameter("id", "email1");
ActionProxy proxy = getActionProxy("/ut/regnlogin/activateUserByEmail.action");
assertNotNull(proxy);
ActivateUserByEmail action = (ActivateUserByEmail) proxy.getAction();
assertNotNull(action);
String result;
result = proxy.execute();
assertEquals(Action.SUCCESS, result);
}
执行结果:
java.lang.NullPointerException
at org.apache.struts2.StrutsTestCase.getActionProxy(StrutsTestCase.java:130)
at com.cnbab.proj118.regnlogin.action.ActivateUserByEmailTest.testExecute(ActivateUserByEmailTest.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
代码执行到
ActionProxy proxy = getActionProxy("/ut/regnlogin/activateUserByEmail.action");
显示空指针,是哪里的问题呀?
路径改成:.... getActionProxy("/ut/regnlogin/activateUserByEmail");
或getActionProxy("/activateUserByEmail.action");
或getActionProxy("/activateUserByEmail");
都还是空指针,是什么原因呢? |
|