I'm currently investigating unit testing in hard-to-reach areas (that's a very high-level view, I know) and I've come up against this question: stubs / mocks or service virtualization?
I'm reading in pursuit of the answer, but the only resources I can find seem to come from SV vendors (who are obviously biased).
Can anyone think of examples when one is absolutely more appropriate than the other, and why? If the answer is "it depends", then please suggest why / what on. It seems like the same results can be achieved either way - it's a question of time (to develop) or available funds (GreenHat etc. aren't cheap!).
Thanks in advance!
EDIT:
Having checked one of the links(1) posted below, I think this is what I'm getting at:
"Virtual services are just test stubs that you can make yourself.
While you can code your own stubs, once you get past very simplistic behaviors the effort and cost of mocking up all the systems you depend on throughout the software development lifecycle becomes overwhelming. Service Virtualization demands automation in that the simulation and modeling can be conducted by direct observation on the part of software rather than requiring manual coding and adjustment. Otherwise, you may be spending as much time maintaining your stub environments as you do building and testing the application functionality itself."
Same as any tool then basically, eh?
Great question. Basically, stubs disconnect a test suite from an environment and service virtualization emulates an environment in order to better exercise the true intent of a test.
In more detail...
Stubs provide replacement implementations for objects, methods, or functions in order to remove external dependencies. Stubs are typically used during unit and component testing for two main purposes: 1) To isolate the code under test from the integrated environment 2) To enable testing to proceed when it is not possible to access an external resource or problematic method/function/object.
If you're trying to write a unit test and need to replace a simple call to a database, external libraries (e.g., file I/O) or other system API, stubbing might be perfectly suited for your needs.
While stubs/mocks are typically used to “skip” unavailable system components, service virtualization allows team members to emulate environments (or specific components) and make their behavior available to the entire team. For instance, service virtualization might be used to emulate the behavior of a dependent component (such as a 3rd-party service, database, mainframe, packaged application, etc.) that is evolving, not yet available, or difficult to access / configure for testing.
Service virtualization can represent much more realistic behavior than simple stubs and mocks. If you can access the dependent application, you can capture its current behavior in a "virtual asset" by recording from the live system. Alternatively, you can model virtual assets that represent the anticipated behavior. You can then configure this virtual asset by parameterizing its conditional behavior, performance criteria, and test data. Moreover, you can easily modify the virtual asset to produce the appropriate assortment of fault conditions, exceptions, etc. that should be exercised in order to validate the full range of system behavior.
Parasoft, the company I work for, addresses both of these use cases. Our Development Testing platform facilitates stub generation and management for unit testing, and our Jolt-award winning Parasoft Virtualize product offers service virtualization. See http://www.parasoft.com/service-virtualization and http://www.parasoft.com/development-testing for details.