Build a easy to unit test the Java-web System

Source: Internet
Author: User
Web recently in a project to do, we are using some seemingly standard WEB structure, DAO (Data Access) + HELPER (processing operations) + ACTION call HELPER layer) + Struts of the control system, the page using struts tags and part of the custom label displaying.

Into the testing phase

1, DAO test -- JUnit is very good, we use the eclipse + JUnit. the jar and was very happy with the completion of this part of the test

2. helper tests-use and the DAO in the same test method to complete test

3. into the action test phase, there is a problem, first, the mapping can not, to switch to strutstestcase, found that the main Cactus approach and
Mock Object approach, using, and found a lot of things cannot be embedded, test simulation framework is not to be able to handle the enough tools, and without a good tool support, the last action part equal to give up, will want to place in combination in the test, how to build a good drive first, the system framework of this time to make a person feel important, reasonable and effective separation of the layers of the class, the layers of the class can be independent of the test and don't need the container, will be to ensure that the quality of the Code is an important part of the hope to be able to have more understanding. organization is using a perfect the quality of the framework of the system.

Combined with the test and some online information, I'm a good framework has some personal views, the struts action in the execute method, should pay attention to use, not every Implementation of the method are also need a mapping, actionform, request. response of the four parameters, should be appropriate to do some method, separate them. in an attempt to make method with the smallest parameter. 2. in order to test the convenient, development should be the appropriate external exposure to some of the interface, let's test the data can be put.





By the way, maybe I 've seen less STRUTS of the testing tool is very inconvenient, also not comprehensive, now the tools are not enough to let users convenient, flexible unit testing.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.