Saturday, November 08, 2008 2:30 PM
My opinion on mocking
In my previous post I asked the question:
"Mock Framework, yes or no?"
I got some answers and now I would like to share with you my opinion.
I think that a mock framework can make the every day unit testing tasks easier. We all know that writing unit tests can be a demanding and exhausting work, right? Well mock objects will come in handy when we need to decouple objects and will surely save time and pain; however it also makes you (in some manner) stop thinking about the architecture / design of your code.
Let me explain my point. While mock framework helps you decouple tightly coupled components in an "artificial" way, it will make you ignore the need of that during the design and coding phase; thus you will end up writing "wrong" code that is still tightly coupled instead of decoupling them by design.
In my opinion there is an alternative. I think that using a "stub" framework can help you in both the every day tasks and the design. The stub framework will generate methods, classes and interfaces that will help you unit test your code. Microsoft has been working on that with Visual Studio and we can now use stub on several types. This surely helps me writing a "good" code in less time.
What do you think?