General

General
What are the specific benefits of VirtualMock over other existing FREE mock object tools and approaches?

(NOTE: Polygenix AgileTest supports some of these features. However, AgileTest is a commercial product.)

  1. The ability to mock up calls to static methods without modifying the design of the code under test (such as making an Adapter, Wrapper, or Facade class with non-static wrapper methods)
  2. The ability to mock up objects which are directly instantiated by the class under test without modifying the design of the code under test (such as using a factory instead of direct instantiation).
  3. The ability to mock up non-static calls to an object without using an interface or passing the object in as a parameter
  4. The ability to mock up calls to final methods
Is VirtualMock the one-size-fits-all, be-all, end-all, swiss army knife of mock object tools and approaches?
NO! Every application and the requirements for unit testing it are different. Although VirtualMock is designed around a certain set of principles, common sense and practicality dictate a hybrid approach - you should use whatever you think are the the best tools and approaches for each particular unit testing scenario. This quote by Eleanor Roosevelt sums it up nicely.
Can VirtualMock be used in conjunction with other mock object tools and approaches?
YES! Every application and the requirements for unit testing it are different. In some cases, you may want to use other approaches to complement the VirtualMock approach, such as using actual mockobject classes such as those provided by mockobjects.com (TODO: link) or MockMaker (TODO: link). VirtualMock is designed to support this type of flexibility.
Why is Aspect Oriented Programming required?
  1. To eliminate the need to refactor or create any code outside of the unit test class (although many people consider this to be a good thing). This can be an advantage over some other unit testing approaches, especially in the case of calls to static methods or direct instantiation of collaborators.
  2. Several features of VirtualMock are not possible with pure java.
Why do I get unexpected warning/failure messages from VirtualMock?
  • Most warnings and failures can be disabled (TODO: insert link to appropriate API methods)
  • If you don't like the functionality of VirtualMock, you can:
  • Submit a bug/enhancement report (TODO: insert link)
  • Modify or subclass the source code to be behave as you would like
  • Use another unit testing tool or approach
I'm suspicious about this Aspect Oriented Programming, bytecode manipulation, and/or custom classloader stuff. How do I know it isn't altering my production classes without me knowing?!?
As long as you use the provided ant/maven tasks correctly or run your tests in an IDE using AJDT (TODO: link), the VirtualMock aspects will not affect or modify your original source in any way. It will only modify the execution of your source if you explicitly tell it to do so as part of the unit test (using VM.init() and other calls). In Ant/Maven mode, it works on a copy of your code. In Eclipse, the modifications are done behind the scenes (and you can disable AspectJ whenever you want).
Why does VirtualMock use static calls instead of being a superclass?
This allows VirtualMock to be used at the same time as other Unit Testing approaches which require the use of a superclass, such as Cactus, or StrutsTestCase (since Java only supports single inheritance).
Why do you use the term "Argument" instead of "Parameter"?

By commonly accepted definitions, an "Argument" is a value recieved by a called function, while a "Parameter" is a value passed by the caller. This is an important distinction when considering pass-by-reference as opposed to pass-by-value, but in most cases it is an irrelevant distinction, especially in easymock where the "real" method is never actually invoked for a mocked call. It's the same football, but you call it something different depending on whether you are kicking or catching it. JavaWorld has a good article describing this issue: Does Java pass by reference or pass by value?. O'Reilly's Java in a Nutshell by David Flanagan puts it best: "Java manipulates objects 'by reference,' but it passes object references to methods 'by value.'".

I chose the term argument because: 1) VirtualMock mostly interacts with values that have already been passed in to mocked or invoked method calls, and are technically considered "arguments" at that point, and 2) more imporantly, "arg" has fewer letters and syllables than "param", and is therefore easier to type and say :)