Automated tests can slow our pressure and enhance confidence in reconstruction. In the J2EE system, the hierarchical designs have been more familiar. In the persistence layer and the business layer test, it is relatively simple. It can be used in JUnit, but involves the web container, such as the test of the Struts section. It's more troublesome, I have always been testing only for the service layer, that is, the FACADE layer is not wrong. My concept of testing on the Web layer has always been considered to be a unit test of a unit test that is incompletely visiting the pressure test, performance test, and does not want to function. Today, come into contact with a new StrutstestCase for Junit, which supports two tests: Provide Mock object methods and CACTUS methods. Not only can you test the implementation of an action object, but you can test mappings, from beans, and forwards declarations. The current version is strutstest2.1.3, as if you only support struts1.1, you need to introduce strutstest-2.1.3.jar and junit.jar . Home is http://sourceforge.net/projects/strutstestcase/
Try the example of it (based on Mock), I feel very easy, you can automatically test the JSP container without starting the JSP container.
// MockStrutsTestCase is extended from the public class TestCase TestLoginAction extends MockStrutsTestCase {public void environment when testSuccessfulLogin () {// set up request reaches this action: request parameters used in the session object, etc. addRequestParameter ( "username", "deryl") AddRequestParameter ("Password", "Radar"); SetRequestPathInfo ("/ login"); // Call the method of the actionPerform (); // assertion forward and expected VerifyWard ("Success"); VerifyForwardPath ("/ main / surcess.jsp"); // Ask if it makes an action that should be made, such as an object in SESSION. Assertequals ("DERYL", getsession (). GetAttribute ("Authentication")); // Asaiced that there is no error to capture verifynoActionerror ();}}
Then you can look at the pleasant green status. Under normal circumstances, it is possible to write a method of TEST verification that has not passed. Since it has not been used in the project, how does its actual effect is still not good, is it able to improve the development efficiency? Anyway, knowing that there is a way of testing Struts is always there harm.