Up until a few months ago I had never even attempted to use
mocks (
NMock,
RhinoMock, etc).
Every time
I would read about Mocking I thought to myself, this is kinda cool, but seems
to be a waste of energy.
At the time I saw Mocks as only a way to create ‘placeholders’
for business/data classes.
I did not
realize that the true power of Mocks was in the ability to isolate code that is
not meant to be tested.
By doing this it
allows the author to write cleaner, more reliable tests.
Needless to say for the first few months of using mocks, I had
to force myself to implement them.
Now, I
choose to do them so that I can have better tests.
In fact, when I am writing new tests, the
first thing I think of is, does any part of this test need to be Mocked?
Unfortunately for me, if the answer is yes, I
tend to have to make changes to our application to allow for easier mocking
(The initial design of the application did/does not allow for easy TDD/Mocking).
Another thing I have learned during my journey into Mocking
bliss, is how TDD and Mocking changes your mindset when designing parts of your
application.
When you are dedicated to using
TDD and Mocking it forces you to attack your architecture from a totally different
angle.
One of the really cool things about our profession is the ability
to grow as a professional every day, if you choose to do so.
For me, learning to use Mocks is just another way I have
grown into a better, more complete professional developer.