A frequent question is when should I use a mock object framework ?
However, if you have to ask "when", the answer is probably "not now". I feel that mock object frameworks are something you have to evolve into.
First, we can talk about mocks in general. Some people have a misconception that mock objects are only useful if you need to simulate interaction with a resource that is difficult to use in unit tests - like an object that communicates with an SMTP server. This isn't true.
* The real object has nondeterministic behavior
* The real object is difficult to setup
* The real object has behavior that is hard to trigger
* The real object is slow
* The real object is a user interface
* The real object uses a call back
* The real object does not yet exist
If we were to step back and generalize this list, we'd say test doubles are useful when you want to isolate code under test. Isolation is good. Let's say we are writing tests for a business component. We wouldn't want the tests to fail when someone checked in bad code for an auditing service the business component uses. We only want the test to fail when something is wrong with the business component itself. Providing a mock auditing service allows us to isolate the business component and control any stimuli the component may pick up from its auditing service. When you start feeling the pain of writing numerous test doubles by hand, you'll know you need a mock object framework.
Mocks aren't just about isolation, however. Mocks can play an important role at any time if employed correctly. Mocks can be powerful technique for identifying types in a system based on the roles that objects play … In particular, we now understand that the most important benefit of Mock Objects is what we originally called interface discovery.
Using a mock object framework allows a continuous, top-down design of software. But Aren't Mock Object Frameworks Complex?
This is another question I've been asked recently. Mock object frameworks are actually rather simple and expose a small API. There is complexity, though, just not in the framework itself. As I said earlier, I think there is a path you can follow where you evolve into using mock object frameworks. The typical project team using a mock object framework is experienced with inversion of control containers. Trying to get up to speed on all these topics at once can be overwhelming.
There is also some complexity in using mocks effectively. In Mocks and the Dangers of Overspecified Software, Ian Cooper says:
"When you change the implementation of a method late in the implementation process, mocks can break because you now make additional or different calls to the dependent component that is being mocked. … The mocks began to make our software more resistant to change, more sluggish, and this increased the cost to refactoring. As change becomes more expensive, we risked becoming resistant to making it, and we risk starting to build technical debt. A couple of times the tests broke, as developers changed the domain, or changed how we were doing persistence, without changing the test first, because they were frustrated at how it slowed their development. The mocks became an impedance to progress."
Mock object frameworks make interaction based testing easy, but can also lead to the problems Ian outlines. Here a couple more reads on this topic:
* Guidelines to Using Interaction Based Testing
* Why Mock Frameworks Suck
In summary – mock object frameworks aren't for everyone. You'll know when you need one!
Idealism is what precedes experience; cynicism is what follows...
Subscribe to:
Post Comments (Atom)
Blog Archive
-
▼
2008
(123)
-
▼
June
(55)
- "Is it Flex ?" Online Service (by James Ward)
- DFUG meeting in Aarhus - Indian Summer Knowledge
- Remembering the pre-AJAX days ?
- 3D Charts Using PaperVision3D (by Andrew Trice)
- Workaholics United : The Two Minute Rule
- Synergy working with Microsoft Windows Vista
- PureMVC : Lazily Instantiated Components
- Adobe Flex : Flex 3 Compiler Design Document
- Adobe Flex : Custom ToolTip Implementation Sample
- Adobe Flex : There is a bug in the Adobe Flex Fram...
- Adobe Flex Resources Tool Suite
- HelloGroup is proud to announce their new website !?
- Xoopit turns your Gmail into a multimedia heaven
- Google Social Graph API
- dotNet : Other New Technologies
- StateMachines : Implementation of WF in AS3
- MyHome Benchmarks with YSlow
- Configuring Flex Builder to use the HellFire compiler
- AIR 1.1 : Now with Localization !
- Google Browser Sync Discontinued in FF 3
- Introducing acrobat.com
- Adobe Flex : Cross-versioning
- The benefits of Functional Design
- Maintenance is more than 3/4 of a successful syste...
- Low Coupling
- Mock Frameworks, not for everyone and everytime
- Adobe Flex : Linkreports
- Silverlight Tour Workshop
- Flex AIR and ActionScript Posters
- Adobe Flex : Flex community-powered Search
- Be your own toolsmith and instrument your applicat...
- HTML Code Formatter
- MSDN : TechEd 2008 in Barcelona
- Adobe Flex : Coding Standards
- Adobe Flex : Remember that the MXML inherits from ...
- Adobe Flex : Never try to manipulate the children ...
- Adobe Flex : Coding Conventions
- Adobe Flex : Never try to removeChildren() that ar...
- Adobe Flex : Event/Action binding in MXML and AS
- Adobe Flex : The Code-Behind Pattern
- Adobe MAX 2008
- ItDepends : A tool for visually exploring the depe...
- FlexCover : A code coverage tool for Flex, AIR and...
- Adobe Flex 4
- Thunderbolt : A logger extension for ActionScript ...
- SVN : Frequency of Update&Commit cycles
- HCI : Morphable Interfaces - The Initial Inspiration
- PureMVC & Cairngorm : Introducing Tech Per
- State Machines : The C in PureMVC
- State Machines : Windows Workflow Foundation
- State Machines : Basic Thoughts
- State Machines : A Powerfull Programming Tool
- Adobe OnAIR Tour Stockholm (2)
- Adobe OnAIR Tour Stockholm (1)
- PureMVC : Pipes : Demo
-
▼
June
(55)
My Network
-
-
Stop dragging me into board meetings - Dear Reader : This might be a bit more NEGATIVE than you’re used to. Apologies about that. I love to chair startups and companies, but I hate 95% board m...9 years ago
-
Design practice makes perfect - Evidence gained from research is powerful. It can persuade the most stubborn board members if presented in a way where decisions can be made based on facts...10 years ago
-
-
dutch vs danish politics - First reaction: glad I don’t live there. And then I made this comparison. It doesn’t differ that much actually. CDA 14% – Konservative 10% VVD 21% – Venstr...14 years ago
-
The Next Web – Timothy Ferriss - First speaker on the last day of The Next Web was Timothy Ferriss, author of the ”4-Hour workweek”. I don’t know what I was really expecting from a guy who ...14 years ago
-
Links for Motorcycle enthusiasts - MC travel-blogs: Must see: http://www.kccd.no/ http://4qconditioning.blogspot.com/ Danish blogs: http://www.ossianbuilds.blogspot.com http://wrenchmonkees....14 years ago
-
New Arduino project - I found myself a new Arduino project – an automated car! Well how to go about this. My best approach was to get a cheap RC toy car from the local toy store...15 years ago
-
Unrecognized selector sent to instance - As you may or may not know, I do iPhone/Cocoa touch now... While playing around with something this evening I stumbled across something I thought I'd share...15 years ago
-
-
-
-
-
-
-
About Me
- Peter Andreas Molgaard
- Copenhagen, Denmark
Labels
- Adobe Flex (62)
- Events (28)
- Best Practices (27)
- ActionScript 3.0 (16)
- Adobe AIR (15)
- Tools (15)
- Workaholics United (14)
- PV3D (10)
- Arbitrary Thoughts (9)
- PureMVC (7)
- Adobe Flex SDK (6)
- Adobe Max (6)
- Methodology (6)
- RIA (6)
- State Machines (6)
- .NET (5)
- Adobe Flex Builder (5)
- DFUG (5)
- Google (5)
- WebORB (5)
- Data Visualization (4)
- Flash Platform (4)
- Independent Thinking (4)
- Process (4)
- SEO (4)
- Silverlight (4)
- Adobe Flash Player (3)
- Code Design (3)
- Flash Player (3)
- HCI (3)
- MAC vs. PC (3)
- Microsoft (3)
- Performance Optimization (3)
- Stockholm (3)
- Undocumentation (3)
- Visual Studio (3)
- Windows Workflow Foundation (3)
- ACE (2)
- AUG (2)
- Adobe Thermo (2)
- Ajax (2)
- Bug Report (2)
- Cairngorm (2)
- Commerciel (2)
- Documentation (2)
- Estimation (2)
- Firefox (2)
- Google Gears (2)
- London (2)
- Morphable Interfaces (2)
- SVN (2)
- SoftwareEngineering (2)
- Test (2)
- Admin (1)
- Adobe Flex Adobe Flex Builder (1)
- Facebook (1)
- Graphics (1)
- Hardware (1)
- HelloGroup (1)
- IEEE (1)
- Outsourcing (1)
- Training (1)
- XAML (1)
No comments:
Post a Comment