MockBox version 1.0 Beta is now on SVN and can be downloaded by downloading the ColdBox Nightly Build found in our download area. Also, in tradition of always bringing you the best documentation and samples, we have our guide ready for consumption. The documentation goes over every feature of MockBox, samples and how to use it. So before I go over some of the features of MockBox, let me give a brief introduction of what a Mock is.
"A mock object is an object that takes the place of a 'real' object in such a way that makes testing easier and more meaningful, or in some cases, possible at all". by Scott Bain (Emergent Design - The Evolutionary Nature of Professional Software Development) http://www.netobjectives.com/emergent-design-evolutionary-nature-professional-software-developmentThat is a great definition by Scott Bain, direct and to the point. So what are the features of MockBox:
The approach that we take with the MockBox is a dynamic and minimalistic approach. Why dynamic? Well, because we dynamically transform target objects into a mock form at runtime. The API for the mocking factory is very easy to use and provides to you a very simplistic approach to mocking. So what can the mock factory do for me?
- Create mock objects for you and keep their methods intact (Does not wipe methods, so you can do method spys, or mock helper methods).
- Create mock objects and wipe out their methods (Wipes out the entire set of methods).
- Create stub objects for objects that don't even exist yet. So you can build to interfaces and later build dependencies.
- Decorate instantiated objects with mocking capabilities (So you can mock targeted methods and properties; spys)
- Mock internal object properties (In any scope)
- Have a method return 1 or more expected results.
- State-Machine Results. Have a method recycle the results as it is called consecutively. So if you have a method returning two results and you call the method 4 times, the results will be recycled: 1,2,1,2
- Method call counter, so you can keep track of how many times a method has been called.
- Method arguments call logging, so you can keep track of method calls and their arguments as they are called.
- Ability to mock private/package methods
- Ability to mock exceptions from methods or make a method throw a controlled exception.
- Ability to change the return type of methods or preserve their signature.
- Ability to make methods return results according to argument signatures
Add Your Comment