struts1的测试(MockStrutsTestCase类)

import java.io.File; import servletunit.struts.MockStrutsTestCase; public class TestLogonAction extends MockStrutsTestCase { protected void setUp() throws Exception { super.setUp(); setContextDirectory(new File("WebRoot")); setRequestPathInfo("/logon"); } public void testSuccess() throws Exception { addRequestParameter("username", "scott"); actionPerform(); verifyForward("success"); verifyForwardPath("/"); assertEquals("scott",getRequest().getAttribute("username")); } public void testFailed() { addRequestParameter("username", "root"); actionPerform(); verifyForward("failed"); verifyForwardPath("/"); assertNull(getSession().getAttribute("username")); } }

你可能感兴趣的:(struts1的测试(MockStrutsTestCase类))