Strutstest:
http://strutstestcase.sourceforge.net/
Strutstestcase: The Tool for struts unit Testing:
http://sourceforge.net/docman/display_doc.php?docid=19672&group_id=39190
Easymock User Manual:
http://dev.9cbs.net/develop/Article/article/28/Article/28/Article/28/Article/28/28583.shtm
Struts is one of several frameworks that are currently used in Web development, and Strutste is specifically responsible for testing the MOCK test framework for the Strut application.
Using the purpose STRTUSTEST is an extension of JUnit, use it, you can easily test the Struts application (container external test) without starting the Servlet container. It also belongs to the use of the Mock object test, but it is different from Easymock that Easymock is an API that provides a Mock object, and StrutStest is dedicated to test the MOCK object test framework for testing the Struts application. In addition to the container test, StrutStest can also be very convenient to test the test in the container. The current version is strutstest2.1.0, and Struts 1.0 is not supported in this release. If you need to test the Struts1.0 application, the corresponding version is Strutstest2.0. You can download from http://sourceforge.net/projects/strutstestcase/.
Usage 1. Basic steps: - Writing struts action. - Determine how to test: Mock objects choose MockStrutStestCase as base classes; CACTUSTRUTSTESTSTCASE; these two modes are the same. - Use Setup and Teardown to initialize, clarify the first sentence of these two functions to call the SUPER method. - Set the path to the Struts Action to be tested, so that strutste can find Web.xml and Struts-related configuration documentation. - Set the Action corresponding to the corresponding PATH name in Strtus-Config.xml. - Set the various parameter values to the Request object to be used in the Action, including the value of the FORMBEAN used by the action. - Execute an action. - Verify that the return path of the action is correct, that is, the name of Forward. - Verify the rest of the Action. 2. Using an example (using a Mock mode): public class departmentDbactionTest Extends MockstrutstestCase {public departmentDbActiontest (String arg0) {super (arg0);
} public void setup () {super.setup ();
/ / Indicate the root of the web application
File ContextFile = New File ("D: // Projects // Fog // Implement // Web"); setContextDirectory (contextfile);
} Protected void tearDown () throws Exception {super.tearDown ();} public void testDoAdd () {// set the action path setRequestPathInfo ( "/ dpEdit"); // setup parameter addRequestParameter formbean the required action ( "method "," doadd "); AddRequestParameter (" PageID "," 1 "); AddRequestParameter (" DPNAME "," Test Department "); AddRequestParameter (" DPTYPE "," Test Department "); AddRequestParameter (" Yn "," N " "); // Execute action actionPerform (); // verify the returned Forward VerifyForward (" Success ");
} 3. Main functions and roles: - setContextDirectory, set the root of the web application - setRequestPathInfo, set request request - AddRequestParameter, add parameters and corresponding values to request - ActionPerform, execute this request - VerifyForward, verify that the name of Forward is correct - VerifyForwardPath, Verify that Forward's Path is correct - VerifyNoActionerRors, verify that there is no actionerror generated during the action execution - VerifyActionErroRRORS, verify that the content of the ActionError collection generated during the Action execution is specifically detailed, please refer to the corresponding javadoc. 4. Test Tile. Its basic procedure is similar to the above, and the difference is that verification: uses VerifyTilesForward and VerifyInputTilesForward.
5. Test the child module. The basic process is also the same as that, differences in the need to specify the struts-config.xml and call mode you need to use: - First, specify the required struts-config.xml: setConfigfile ("MyModule", "/ WEB-INF / STRUTS-Config-MyModule.xml ");
- Second, specify the path to the call: setRequestPathInfo ("/ mymodule", "/ login.do");
Check the table Use StrutStest to pay attention to: - In TestCase, you can access the request, session, etc., StrutStest provides us with access interface. - JUnit's Assert function and FAIL function can be used in Strutstest. - For file upload, the current StrutStest doesn't have any particularly good solution. See the Strustest's FAQ.