Seam integration test

Source: Internet
Author: User
Seam integration test

Seam integration test
Integration Testing
Integrated Testing and unit testing are used together. It should integrate test units. In fact, most integration tests simulate client calls. Therefore, you can have a complete functional test, from the presentation layer to the business logic layer, to the persistence layer.
These tests are very useful and can be further developed to adjust the backend system. It immediately shows you whether your changes at the business layer will affect web page interruptions. Of course, it depends on whether you update the test in time. Once you update the JSF page, you should also change the test accordingly.
To perform an integration test, use a combination of testng and seam base classes to simulate faces requests. This example also uses the previous unit test example. Integrate the test run to add a house. Java code
  1. Public class housetest extends seamtest {
  2. @ Test
  3. Public void testaddhouse () throws exception {
  4. New facesrequest (){
  5. @ Override
  6. Protected void processvalidations () throws exception {
  7. Validatevalue ("# {house. Address}", "123 Main Street ");
  8. Validatevalue ("# {house. City}", "Columbus ");
  9. Validatevalue ("# {house. State}", "oh ");
  10. Assert! Isvalidationfailure ();
  11. }
  12. @ Override
  13. Protected void updatemodelvalues () throws exception {
  14. Setvalue ("# {house. Address}", "123 Main Street ");
  15. Setvalue ("# {house. City}", "Columbus ");
  16. Setvalue ("# {house. State}", "oh ");
  17. }
  18. @ Override
  19. Protected void invokeapplication (){
  20. Assert invokemethod ("# {salesmanager. addhouse}"). Equals ("success ");
  21. }
  22. @ Override
  23. Protected void renderresponse (){
  24. Assert getvalue ("# {house. Address}"). Equals ("123 Main Street ");
  25. Assert getvalue ("# {house. City}"). Equals ("Columbus ");
  26. Assert getvalue ("# {house. State}"). Equals ("oh ");
  27. }
  28. }. Run ();
  29. }
  30. }

The first thing is to inherit seamtest, which is part of the seam core class. After inheriting this class, you can use two core operations to create a request. You can use a superclass to create a facesrequest or nonfacesrequest. These two classes are the internal classes of the seamtest object. We will create the class implementation and call it through the override method. Each method call represents part of the JSF lifecycle. This method can be intercepted to test each part of the request. Method:
Getviewid () JSF view ID or the name of the page requested by non-Faces
Applyrequestvalues () application request value stage defines the interaction between JSF and component pages
Processvalidations () method for processing the verification phase
Updatemodelvalues () method for updating model values
Invokeapplication () is used to call methods and override methods.
Renderresponse () appears during the response
You can select the method to overwrite. In the example, we verify and set the value to pass to the business layer, set the value in the House object, verify the item, and then provide the House object to the database.
In the long run, testing can save valuable time. It helps identify errors and abnormal behavior of applications, especially in large projects where testing takes a considerable proportion of the time.

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.