spring +struts2 +junit 的测试 StrutsSpringTestCase 使用问题
spring +struts2 +junit 的测试这个地方出现问题:getActionProxy("/member/ClientLogin.action");
异常情况为:
There is no Action mapped for action name ClientLogin. -
at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:178)
at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:47)
at org.apache.struts2.StrutsTestCase.getActionProxy(StrutsTestCase.java:137)
at com.ttuan.action.member.TestClientLogin.testCleientLogin(TestClientLogin.java:28)
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:585)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:243)
at junit.framework.TestSuite.run(TestSuite.java:238)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
ClientLogin在
ActionMapping mapping = getActionMapping("/member/ClientLogin.action");
System.out.println(mapping.getName());
中有输出的!
请高手指点下问题在哪?
public class TestClientLogin extends StrutsSpringTestCase {
@Override
protected String getContextLocations() {
return "conf/application-test.xml";
}
public void testCleientLogin() throws Exception {
request.setParameter("username", "FD");
ActionMapping mapping = getActionMapping("/member/ClientLogin.action");
System.out.println(mapping.getName());
assertNotNull(mapping);
request.setParameter("username", "FD");
ActionProxy proxy = getActionProxy("/member/ClientLogin.action");
System.out.println("ssss");
assertNotNull(proxy);
ClientLogin action = (ClientLogin) proxy.getAction();
assertNotNull(action);
// String result = proxy.execute();
// assertEquals(Action.SUCCESS, result);
// assertEquals("FD", action.getUsername());
}
}
这个提示很名下啊,没有对应的匹配的action。估计是丢了spring里的action内容。 看下你的struts.xml中关于namespace和action名字的配置信息
页:
[1]