Extreme JS

JS Greenwood's WebLog on architecture, .NET, processes, and life...

When TDD Goes Bad #2

I've been debating whether to post another entry on this for the last couple of weeks due to another bad smell I've spotted around Agile practices.  However, it's my blog, and I think it's worth saying.  But first, the bad smell...

Zealotry.  Many advocates of Agile practices have had to fight their corner hard against supporters of traditional methodologies.  Having had several such confrontations myself, it does become tiring, and you do beging to expect fairly incongruent arguments against it.  There is a danger, though, that the habit of dealing with arguments against Agile that don't stack up will lead to a blinkered view where it's assumed that any negative statement about the principles and approach should be dismissed.  No methodology is perfect - different circumstances call for different approaches, etc.  Also, just because a methodology when applied correctly is appropriate and should result in success, it doesn't mean that it will be applied correctly and appropriately.  People can, and will, get things wrong - especially when lacking experience.

So, TDD Gone Bad #2...  Mock oriented development.  Mocks are a good thing where you really want to extract a dependency and ensure you're testing the right thing.  But there are a couple of issues that can arise:

  1. Poor integration tests, as everything is being tested in isolation - we can end up with a system where the constituent parts are clean, isolated, well tested, and known to be correct.  But how they fit together is a greyer (or even blacker) area unless mocking is accompanied with a complement of integration tests. Dave describes this well in his blog, so there's no need for me to go on about it here: http://www.twelve71.org/blogs/dave/archives/000616.html
  2. Mock oriented design.  Whilst mocking is good at removing dependencies, their introduction regularly alters the design of the system.  I've seen numerous occasions where the introduction of mocks has added a large amount of complexity to an otherwise simple design.  This complexity leads to higher implementation costs, a higher cognitive load on the developers working on the system, and higher maintenance costs (as there's more code to maintain).  All of which go against the principle of "the simplest thing".  The irony is that the introduction of mocking can, sometimes, make completing a system far more time consuming due to the different levels of granularity, and the additional code required to implement interfaces, etc.  Again, that's not to say mocks aren't very useful things, just that they're a tool to be used where appropriate, not a pattern to base the foundations of your entire implementation on...

Whenever mocking is used, the value that the mock gives versus the cost it will introduce over the lifetime of the system should be measured (or at least estimated/considered)

Posted: Dec 29 2004, 10:35 PM by jsgreenwood | with 54 comment(s)
Filed under:

Comments

Thomas Eyde said:

I have read your TDD gone bad posts a couple of times now, and have let it sink in. The more I think of it, I have to admit you do have a point. I also read the article "Goal 1 - Mission 0", which I think touches the same issue.

I have have gone in the trap of thinking I have to test everything. And because I want every test to be isolated, that means a lot of mocking.

What I discovered was that my tests digs too deep into the implementation and no longer tests just external behaviour. That means my tests are coupled to the implementation, which is not how it should be.

Ron Jeffries latest bowling game articles, where he reuse the very same tests to explore different implementations and designs, shows it very well how it should be.

So a simple test on the tests: If I can't use them to implement a totally different design, then they are too coupled to the implementation.

Perhaps this is a testing smell or anti-pattern?
# December 30, 2004 3:38 PM

JS Greenwood said:

Thomas - totally agree. One of the most disheartening (TDD) things I've ever seen was when a design had evolved that was clearly not fit for purpose given the latest set of requirements. Unfortunately, a change in design could not be made because of the cost of reimplementing tests against the new design. Rather than testing the business requirements, it was the implementation detail that was being tested. I see misuse of mocking as contributing to that greatly, as it lets you delve much deeper into the system, rather than testing inputs + outputs.

When it comes to mocking, I generally work on the principle that if you have end to end ownership and visibility of the system, that mocking *may* not be necessary at all. It really comes into its own where external integration is required, or the output from a system isn't measurable.
# December 30, 2004 4:17 PM

Jordan Vinarub said:

The increased dialog on the subject is great, b/c it brings to light all the positives and negatives that are really there. The crux of this discussion is that it's important to not be blindly religious to any approach, or we fall victim to misapplying something when it is not valuable. A hammer is an excellent tool when we want to drive a nail in that probably doesn't need to be extracted. If it does need to be extracted, a drill and a screw would work better. Neither the hammer nor the drill is better, they just fit better for the situation.

TDD is an excellent new tool and we should be really examining where we can use it. The fear of misapplying this tool should not stop us from learning and improving. JS Greenwood is correct in that people will do it incorrectly, but fear of failure should never hold us back from progress.

I say let's keep the dialog going, and find a way to make this new tool work.
# December 31, 2004 8:25 AM

Rob Styles said:

James,

It would be great to see some examples - ideally code - of designs with and without mocking to illustrate the issues you describe. I'm mainly interested in the Mock Oriented Design paragraph - code samples to illustrate that would be very helpful.

cheers

rob

# January 2, 2005 4:42 PM

JS Greenwood said:

Rob,

Sorry, for the delay; I'd not noticed the comment on this post following all the XPSS shenanigans. I'll try and find a good real-world example as soon as I get an opportunity - will have to be careful to pick which (prior) employer I'll pick a non-sensitive one from, mind... :)

However, a general thing that I've spotted that really irks me is the increased usage of interfaces, if mocking is being done based on that (rather than inheritance). As far as I'm concerned, interfaces should be saved for where you definitely _do_ want to be able to replace one implementation with another. If they are only defined and implemented to support mocking, then I feel that the simplicity of the design has very much been compromised for the tests. Not least because there're then security implications of having anything supporting that interface being "pluggable", along with cost & maintenance issues around now having to test that the interface, and so on.
# January 7, 2005 1:10 PM

TrackBack said:

# January 9, 2005 8:03 PM

Christian said:

While I fairly new to the mocking game I believe that there's a commercially available mock framework (POCMock) that allows you to mock .Net classes and static methods, etc without having to alter your design to accommodate your unit tests.

I strive to write grey box tests that take into account my intimate knowledge of the code I'm testing / designing but test input/outputs for verification rather than start inspecting the guts of the objects.

Chirstian
# January 17, 2005 1:51 PM

TrackBack said:

^_^,Pretty Good!
# April 9, 2005 11:59 PM

Tim Ellison said:

>> a general thing that I've spotted that really irks me

>> is the increased usage of interfaces,

I have to agree with JSG on this statement.  Our design on our current project definitely has an increased number of interfaces.  In addition, there are a number of factories that instantiate the correct instances (MOCK or real).  On the other hand, we are absolutely assured of the interaction between the system and each of the interface implementations.

MOCKing is similar to design patterns though. Just be smart with them.

# June 27, 2007 9:54 PM

nTMia said:

On you place I would share such kind of supreme release like this good post utilizing the <a href="http://www.4submission.com">article submit</a>.

# January 25, 2010 6:21 PM

web design company said:

Beautiful post to read, although the information is really good and useful to read, excellent work this is.

Hey, very nice website. I actually came across this on Bing, and I am happy I did. I will definitely be coming back here more often. Wish I could add to the conversation.

# February 5, 2011 6:40 AM

Cheap Article Writing said:

I have read all the posts and i found very unique information

on this blog good work by your side thanks for your views these

are very helpful for those who don't know as much whenever i

wanna share or discuss something i surely come back and

discuss on this blog.

Regards

<a href="http://www.cheaparticlewriting.com">Cheap Article Writing Services</a> .

# March 16, 2011 9:20 AM

marven niffi said:

I feel that the simplicity of the design has very much been compromised for the tests.

# April 2, 2011 6:02 AM

chaster matt said:

Their debut album,, has been released on several record labels, including International DJ Gigolo, Ministry of Sound and Capitol Records, and includes their hit singles "Sweetness", "Emerge", and a cover of Wire's "the 15th". In the final months of 2004, Fischerspooner opened up their FS Studios in New York City to the public for a few hours once a week, allowing people to meet the band and production team, as well as preview new video, music and dance projects that they were working on.

# April 4, 2011 5:04 AM

logo design said:

I have read all about it ,Its very helpful and interesting .

# April 12, 2011 1:59 AM

Company logo design said:

You are a Great while writing in the blogs it is awesome I liked it too much good and informative thanks for the sharing.

# May 4, 2011 8:13 AM

logo design said:

I have to agree with JSG on this statement.  Our design on our current project definitely has an increased number of interfaces.  In addition, there are a number of factories that instantiate the correct instances (MOCK or real).  On the other hand, we are absolutely assured of the interaction between the system and each of the interface implementations

# May 10, 2011 3:02 AM

Credit card debt settlement said:

i have read this article..i really like it...

# May 16, 2011 7:51 AM

best android apps said:

There seems to be a new Android smartphone being released almost monthly and the number of Apps continues to grow.

# May 18, 2011 1:23 PM

Dansk bygherrerådgivning said:

This is really informative and thank for sharing the article and this great link www.twelve71.org/.../000616.html

Cheers

Dansk bygherrerådgivning

# May 27, 2011 1:51 PM

Self assessment tax return said:

I really enjoy reading your blog. This post, even if old, was really useful.

# June 18, 2011 9:57 AM

Bonbons said:

I’m impressed, I need to say. Actually rarely do I encounter a blog that’s both educative and entertaining. Cheers from France!

# June 21, 2011 10:44 AM

ngan hang said:

I found your website perfect for my needs. It contains wonderful and helpful posts. I have read most of them and got a lot from them.

# June 22, 2011 5:16 AM

Donella Kulinski said:

The very heart of your writing while appearing reasonable originally, did not settle appropriately with me personally right after some time. Someplace throughout the sentences you truly managed to make me a believer but only for a short whilst. I nevertheless have got a dilemma together with your leaps in logic and you may do nicely to fill in those breaks. In case you really can accomplish that, I could surely be fascinated.

# July 2, 2011 10:43 PM

Morgan Thillet said:

Excellent blog! I genuinely love how it really is simple on my eyes together with the info are well written. I am questioning how I might be notified whenever a brand new post has been produced. I have subscribed to your rss feed which should do the trick! Have a nice day!

# July 4, 2011 10:12 PM

Asbestos Training said:

I am so thrilled for having found your site.

# July 5, 2011 8:14 AM

Asbestos Training said:

I am so thrilled for having found your site.

# July 5, 2011 8:22 AM

Thaddeus Teppo said:

Greetings! This is my 1st comment here so I just wanted to give a quick shout out and say I genuinely appreciate reading by way of your posts. Can you suggest any other blogs that deal with the identical topics? Thanks for your time!

# July 5, 2011 11:29 AM

Erline Mordecai said:

Very beneficial posting Excited for extra content articles inside your web page.

# July 8, 2011 8:21 AM

Katy perry Tickets said:

You have done really nice job. There are many people searching about that now they will find enough sources by your tips.

# July 14, 2011 2:49 AM

android tablet said:

Good post. Very impressive. Thanks for sharing.

# July 27, 2011 11:46 PM

cheap android tablet said:

Good post. Very impressive. Thanks for sharing.

# July 27, 2011 11:54 PM

id theft protection said:

Thanks for taking the time to discuss this, I feel strongly about information and love learning more on this. If possible,it is very helpful for me.

# August 5, 2011 6:57 AM

Tax Return said:

Your point of view on this subject is really original.

# August 11, 2011 5:04 AM

Discount Sugarland Tickets said:

Your post is knowledgeable… I really appreciate the way you write . I would like to read more from you.

# August 18, 2011 4:09 AM

Asbestos Removal said:

I can not keep this blog just for myself, so I'll forward it to all of my friends.

# August 20, 2011 9:31 AM

hooher tod said:

Yes there should realize the reader to RSS my feed to RSS commentary, quite simply

# September 5, 2011 5:28 PM

Consultant ERP said:

I can't wait to read your next post on this topic.

# September 7, 2011 3:32 AM

Office Supplies said:

You're such an amazing blogger. You should write as often as possible.

# September 8, 2011 5:39 AM

Cheap oem software said:

pBuu2o I serched through the internet and got here. What a wonderful invention of the mankind. With the help of the network you communicate, learn, read !... That helped us to get  acquainted!...

# September 24, 2011 8:00 AM

Find a tradesman app said:

I am in love with eveyrthing you write.

# September 25, 2011 5:24 PM

eid wishes said:

hey,this is one of the best posts that I’ve ever seen; you may include some more ideas in the same theme. I’m still waiting for some interesting thoughts from your side in your next post.

# October 21, 2011 2:47 AM

erik.kriss24@gmail.com said:

The post is actually the freshest on this laudable subject. I harmonize with your conclusions and will thirstily look forward to see your approaching updates.

# October 21, 2011 7:37 AM

testifyerisback said:

Original commissionnaires de transport fini vers le haut de mineur plus grand que les agents gauches de dédouanement groupés à travers clef met en communication comme le Port de Londres, de Liverpool et de Southampton.    

http://www.testifyer.com

# October 21, 2011 6:19 PM

Red Bull Hats said:

All inclusive travel deals are not for everyone,

but most people enjoy a vacation that is put together for them

I am a blog beginner. I am also interested in such kind information. You provide me a good example. Thanks very much. I will keep on reading your blogs.

# October 26, 2011 9:29 PM

Cheap oem software said:

12zVSf Yeah, it is clear now !... From the very beginning I did not understand where was the connection with the title !!....

# November 6, 2011 2:15 AM

home room additions said:

Yes, the main aim is for webmasters to submit their sites to gain links and hopefully higher ranking on the search engines. Hope this answers your question, I am kind of new on the forums and still trying to gain knowledge.

# November 10, 2011 6:09 AM

Eme Michael said:

Hello I Really Like Your Post. For Those Who Enjoy Statuses On Facebook, We're Just Trying To Make New Status And I really Hope you will definitely like our Statuses. And You Can Also Get Latest Statuses From <a href="www.123status.com/">Facebook Status</a>.

# November 14, 2011 1:40 AM

swing sets said:

I wanted to say that it's nice to know that someone else also mentioned this as I had trouble finding the same info elsewhere. This was the first place that told me the answer. Thanks.

# November 19, 2011 4:11 AM

Snowflake Earrings said:

This blog post is excellent probably because of how well the subject was developped. I like some of the comments too though I would prefer we all stay on the suject in order add value to the subject! Phil Wane

# November 21, 2011 6:29 AM

spa offers dubai said:

Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It's always nice when you can not only be informed, but also entertained! I'm sure you had fun writing this article.

# November 24, 2011 7:29 AM

Net Framework 4 said:

The very heart of your writing while appearing reasonable originally, did not settle appropriately with me personally right after some time. Someplace throughout the sentences you truly managed to make me a believer but only for a short whilst. I nevertheless have got a dilemma together with your leaps in logic and you may do nicely to fill in those breaks. In case you really can accomplish that, I could surely be fascinated.

# December 16, 2011 5:42 PM

Buy microsoft software online said:

9AvaAF Totally agree with you, about a week ago wrote about the same in my blog..!!

# December 27, 2011 9:41 PM

Male Breast Reduction said:

I like this blog very much and I'd be really glad to read some newer posts of yours.

# January 11, 2012 2:24 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)