BT

Service Virtualization as an Alternative to Mocking

by Jonathan Allen on Apr 22, 2013 |

Mocking via dependency injection is often a messy endeavor. For even the simplest of applications it often involves creating new interfaces, taking on a dependency on an IoC Container, and in general adds a lot of unnecessary complexity. And after all that, you still have to write the mocks themselves, many of which aren’t useful for anything besides simplistic unit tests.

Products such as CA Lisa Service Virtualization offer an alternative approach. Rather than mocking individual classes, these testing tools allow you to mock entire services at the network level. From the application’s perspective it is talking to a real service backend, even though in reality that backend may not even exist yet.

There are two common ways of setting up a virtualized service. The first is to start with the contract (e.g. a WSDL or other protocol-specific descriptor) and create pre-determined responses. This can be done manually using normal Java or .NET code, or you can use a commercial product. An advantage of this method is that the team writing the component doesn’t have to wait for the real version of the service to be completed. The downside is that the real version needs to actually match the fake one, which becomes a questionable proposition as timelines become longer.

The other route is to use traffic recordings. A tool sits between the component under test and its down-stream dependencies. This tool basically acts as a proxy, gathering information about how the components interact. Later those recordings can be used to simulate the conversation between the component and the servers it depends on.

Both routes are viable for most communication protocols. With the right plugins and filters, the test tool should be able to understand message queues, REST, SOAP, raw TCP, or any other means of exchange.

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

each has there place by Peter Taylor

I think mocking makes sense at a unit test level. Good IOC containers have a great deal of value and rarely do harm. Loosely coupled code is the key to success. When you are ready to think about integration testing then service virtualization makes sense.

IBM also have a commercial offering in this space called Rational Integration Tester.
Peter Taylor
An IBM employee not speaking on behave of IBM

Re: each has there place by Jonathan Allen

If you would be interested in writing a short article about Rational Integration Tester please contact me at jonathan@infoq.com. I'm sure many of our readers would find that product to be useful.

mocktail - Open source service-virtualization solution by ShriKant Vashishtha

We have been working in this space for quite a while to create an open-source solution for Java platform. The solution not only virtualises the web-services response the way Lisa does but at also potentially generic solution for any external interface. You can virtualise the database also which is handy when you want to record a test case with production scenario and prod-db may not be available.

Currently it's in beta but will be available soon.

mocktail.svashishtha.com/
github.com/vashishthask/mocktail/

Re: mocktail - Open source service-virtualization solution by Jonathan Allen

Send a note to Charles Humble, our lead editor for Java news, once it's ready. I'm sure he would be interested in it.

www.infoq.com/about

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

4 Discuss

Educational Content

General Feedback
Bugs
Advertising
Editorial
InfoQ.com and all content copyright © 2006-2014 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT