testhelloactionmultiple.java

来自「介绍如何用strutstestcase工具来测试struts应用」· Java 代码 · 共 42 行

JAVA
42
字号
package hello.mocktest;

import servletunit.struts.MockStrutsTestCase;

public class TestHelloActionMultiple extends MockStrutsTestCase {

    public TestHelloActionMultiple(String testName) { super(testName); }

    public void testNoParameters() {

       // Basic test to illustrate functionality
       setRequestPathInfo("/HelloWorld");
       actionPerform();
       verifyInputForward();
       // Test Form Bean validations
       verifyActionErrors(new String[] {"hello.no.username.error"});

    }

    public void testBadPerson() {

       // Now test Talking to the Bad Person ("Monster")
       addRequestParameter("userName","Monster");
       setRequestPathInfo("/HelloWorld");
       actionPerform();
       verifyForward("SayHello");
       verifyActionErrors(new String[] {"hello.dont.talk.to.monster"});

    }

    public void testHappyPath() {

       // Now test the "Happy Path"
       addRequestParameter("userName","Weiqin");
       setRequestPathInfo("/HelloWorld");
       actionPerform();
       verifyForward("SayHello");
       verifyNoActionErrors();

   }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?