My opinion on mocking

8 בנובמבר 2008

תגיות:
2 תגובות

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?

kick it on DotNetKicks.com

הוסף תגובה
facebook linkedin twitter email

כתיבת תגובה

האימייל לא יוצג באתר. (*) שדות חובה מסומנים

2 תגובות

  1. Roy8 בנובמבר 2008 ב 18:20

    What "Stub" framework has MS done? got any link?

    להגיב
  2. Chad Myers26 בנובמבר 2008 ב 10:12

    > "We all know that writing unit tests can be a
    > demanding and exhausting work"

    This was my experience before TDD and following design principles like the SOLID principles, but not so much afterwards.

    > "however it also makes you (in some manner)
    > stop thinking about the architecture /
    > design of your code."

    I don't understand this statement. Why would mocking make you stop thinking about design?

    להגיב