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
- Public class housetest extends seamtest {
- @ Test
- Public void testaddhouse () throws exception {
- New facesrequest (){
- @ Override
- Protected void processvalidations () throws exception {
- Validatevalue ("# {house. Address}", "123 Main Street ");
- Validatevalue ("# {house. City}", "Columbus ");
- Validatevalue ("# {house. State}", "oh ");
- Assert! Isvalidationfailure ();
- }
- @ Override
- Protected void updatemodelvalues () throws exception {
- Setvalue ("# {house. Address}", "123 Main Street ");
- Setvalue ("# {house. City}", "Columbus ");
- Setvalue ("# {house. State}", "oh ");
- }
- @ Override
- Protected void invokeapplication (){
- Assert invokemethod ("# {salesmanager. addhouse}"). Equals ("success ");
- }
- @ Override
- Protected void renderresponse (){
- Assert getvalue ("# {house. Address}"). Equals ("123 Main Street ");
- Assert getvalue ("# {house. City}"). Equals ("Columbus ");
- Assert getvalue ("# {house. State}"). Equals ("oh ");
- }
- }. Run ();
- }
- }
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.