51Testing软件测试论坛

标题: spring +struts2 +junit 的测试 StrutsSpringTestCase 使用问题 [打印本页]

作者: zhangxy06    时间: 2011-1-21 17:31
标题: spring +struts2 +junit 的测试 StrutsSpringTestCase 使用问题
spring +struts2 +junit 的测试
这个地方出现问题:getActionProxy("/member/ClientLogin.action");
异常情况为:
  1. There is no Action mapped for action name ClientLogin. - [unknown location]
  2. at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:178)
  3. at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
  4. at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
  5. at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:47)
  6. at org.apache.struts2.StrutsTestCase.getActionProxy(StrutsTestCase.java:137)
  7. at com.ttuan.action.member.TestClientLogin.testCleientLogin(TestClientLogin.java:28)
  8. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  9. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  10. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  11. at java.lang.reflect.Method.invoke(Method.java:585)
  12. at junit.framework.TestCase.runTest(TestCase.java:168)
  13. at junit.framework.TestCase.runBare(TestCase.java:134)
  14. at junit.framework.TestResult$1.protect(TestResult.java:110)
  15. at junit.framework.TestResult.runProtected(TestResult.java:128)
  16. at junit.framework.TestResult.run(TestResult.java:113)
  17. at junit.framework.TestCase.run(TestCase.java:124)
  18. at junit.framework.TestSuite.runTest(TestSuite.java:243)
  19. at junit.framework.TestSuite.run(TestSuite.java:238)
  20. at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
  21. at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
  22. at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
  23. at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
  24. at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
  25. at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
  26. at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

复制代码

ClientLogin  在
ActionMapping mapping = getActionMapping("/member/ClientLogin.action");
System.out.println(mapping.getName());
中有输出的!
请高手指点下问题在哪?

  1. public class TestClientLogin extends StrutsSpringTestCase {

  2. @Override
  3. protected String getContextLocations() {
  4. return "conf/application-test.xml";
  5. }

  6. public void testCleientLogin() throws Exception {
  7. request.setParameter("username", "FD");
  8. ActionMapping mapping = getActionMapping("/member/ClientLogin.action");
  9. System.out.println(mapping.getName());
  10. assertNotNull(mapping);

  11. request.setParameter("username", "FD");
  12. ActionProxy proxy = getActionProxy("/member/ClientLogin.action");
  13. System.out.println("ssss");
  14. assertNotNull(proxy);


  15. ClientLogin action = (ClientLogin) proxy.getAction();
  16. assertNotNull(action);


  17. // String result = proxy.execute();
  18. // assertEquals(Action.SUCCESS, result);
  19. // assertEquals("FD", action.getUsername());
  20. }
  21. }
复制代码

作者: archonwang    时间: 2011-1-28 15:44
这个提示很名下啊,没有对应的匹配的action。估计是丢了spring里的action内容。
作者: aman_cao    时间: 2011-8-4 09:26
看下你的struts.xml中关于namespace和action名字的配置信息




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2