Saturday 30 June 2007

Importance of stub services

Todays world of software engineering involves communication with different applications accross different domains. Lots of time is wasted in integrating with the realtime applications in the development environment. The development and testing of our applications is hindered because of the unavailability or issues not related to our application.
The best way to avoid this is to go for the creation of stubs for all the third party services in the beginning of the development cycle. These stubs should be developed by creating a sample response that will be returned by the 3rd party. For eg.
Here is the sample code for a real web service:

[WebMethod]
public response CheckAvailability(request) {
//Actual Business Logic
...
...
...
return response;
}

The above code can be replaced by a stub service as follows:
[WebMethod]
public response CheckAvailability(request)
{return sampleResponse;}

This leads to a heavy reduction in loss of time in fixing of the issues in the actual service. The best usage of this approach is of performance testing of the application. The performance testing can be done using the stubbed services to deterime the actual resource usage by our application without taking into consideration the behaviour of the external services. If a delay of 2 sec. in response from the external service is required, same can be achieved as follows:
[WebMethod]
public response CheckAvailability(request)
{Thread.Sleep(2000);
return sampleResponse;}

This approach can be further extended to test the individual components/layers in our application by stubbing out the other components/layers. The usage of stubbed or actual service can be made configurable by using a config setting. Other way is to host them on different urls and change the urls as per the requirement.

No comments: