aspose file tools*
The moose likes Testing and the fly likes Creating Mocks for Testing Application using Sockets for Data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Creating Mocks for Testing Application using Sockets for Data" Watch "Creating Mocks for Testing Application using Sockets for Data" New topic
Author

Creating Mocks for Testing Application using Sockets for Data

Tarun Khandelwal
Greenhorn

Joined: Feb 23, 2012
Posts: 19
Hello,

I have to test my application.
It uses data from another application through Socket Connection.
I don't want to install this application, So how can i mock the Socket Service easily.
One way that i know is to create a local service that will work same as actual service by creating local ServerSocket.

Is there any way i can do that, just like mocking db connections, so that i don't have to take care of synchronizing Sockets and there Streams.

Thanks,
Tarun Khandelwal
Tim Cooke
Bartender

Joined: Mar 28, 2008
Posts: 1001
    
  47

Hi,

I would wrap the code in your application that deals with connecting to this external application using an Adaptor/Wrapper [GoF: Design Patterns]. By doing so then your main application domain code can integrate with the interface of your adaptor rather than the Socket stuff directly which means you are then free to swap the adaptor out with a Test Double when testing.

So instead of this sort of system architecture:
Application Domain --(Socket Connection)--> External Application

You have:
Application Domain --> ExternalApplicationAdaptor --(Socket Connection)--> External Application

The idea is that for testing you can swap out the ExternalApplicationAdaptor with a Test Double that does not depend on the external application and that you have full control over.
Application Domain --> ExternalApplicationAdaptorTestDouble

You can now manipulate the ExternalApplicationAdaptorTestDouble to behave in whatever manner you require to test the behaviour of your ApplicationDomain

Hope that helps
Tim


Tim Driven Development
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Creating Mocks for Testing Application using Sockets for Data