测试Action

1、添加jar

struts2-junit-plugin-2.1.8.jar             //struts
org.springframework.core-3.0.3.RELEASE.jar //spring
org.springframework.test-3.0.3.RELEASE.jar //spring

2、ActionTest extends StrutsTestCase or StrutsSpringTestCase

非ioc action用StrutsTestCase,否则用StrutsSpringTestCase

3、编写测试方法

@Test
    
public void testExecute() throws Exception {
        ActionProxy proxy = null;

        request.setParameter("param", "test...");
        proxy = getActionProxy("/test.action");
        String result = proxy.execute();
        assertEquals("success", result);


        TestAction test = null;
        test = (TestAction)proxy.getAction();
        assertEquals("test...", test.getParam());
    }

你可能感兴趣的:(spring,ant,struts,JUnit,IOC)