Jeremy D. Miller -- The Shade Tree Developer

Sponsors

The Lounge

News

Advertisement

Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
So How do You Introduce TDD into an Organization or Team?

There's an interesting thread going on in the Yahoo TDD group started by Jay Flowers about introducing TDD to a large organization, and an interesting spawned thread about TDD without OO.  I made a tangential post last week that's referenced - How much design before unit testing, and how much design knowledge before TDD?

I'm not necessarily the best person to ask about this because my experiences haven't been typical.  More than anything else, the critical factor is an organization or team of developers that is open and willing to doing TDD.  Management support would be nice, but in the end it's the developers who are going to make it succeed or fail.  I had it relatively easy because my introduction to TDD came as a consultant with ThoughtWorks, one of the leaders of all things Agile.  A key factor for me joining my present employer was their desire to adopt Agile processes.  The support for TDD was there from day one, at least from development management.  Add in a group of developers who all believe in TDD, or at least willing to give it a try, and you can achieve a pretty smooth adoption rate.   

Coming in and laying down the law, "You will do TDD starting now!" probably isn't going to fly.  Actually, I'll say it more strongly -- TDD won't take without some kind of consensus from the developers.

You might not have it that easy, but then again, the wealth of free information and TDD lore that's available on the web and blogosphere dwarfs the information that was available way back in 2003 when I was writing hopelessly tangled tests.

A team bootstrapping itself will probably struggle at first.  For best results, you're going to have to get some coaching to the TDD newbies.  Most people, myself included, struggle at first with TDD when you start encountering nontrivial enterprise development tasks like persistence and integration.  Brown bag sessions (especially if the team takes turns presenting) and training will help, but for my money, you want a sprinkling of people who can coach TDD and get them paired up with the folks who are new to TDD.  If you don't have anybody who can coach, it might be worth the cost of bringing in an external TDD coach to work hand in hand with the team members.  Regardless of the experience level that your team has, I'd very strongly consider adopting pair programming as a way to disseminate knowledge.  One of the advantages of pairing is the propagation of tricks -- IDE shortcuts, ReSharper features, and TDD idioms for testing code.  For example, I learned how to use NMock for unit testing with external dependencies by pairing with someone who was familiar with NMock.  As a direct result, I immediately got faster.  Even part time pairing will help. 

Going in to TDD, you're going to want an open-minded attitude about the way you code.  In other words, start with an assumption that you will have to change the way you code and design software.  I certainly wouldn't say that TDD is the silver bullet for perfect software designs, it's more like a white glove test that finds all of the tightly coupled dirt and gunk in your design.

Learn Unit Testing First, or Go Straight to TDD

Jay Flowers talks about two camps in his organization, one camp who wants to concentrate on doing unit testing first before moving to TDD while a second group wants to go directly to TDD.  My vote is actually on going straight to TDD.  Most of the challenge in writing automated unit tests is writing code that can be tested.  Putting an emphasis on writing the unit tests first keeps testability (and hence a strong focus on loose coupling) in the forefront of a developer's mind.  Retrofitting unit tests to existing code is hard, period. 

OOP as a prerequisite for TDD

On the Yahoo thread I linked to, several folks are challenging my opinion that TDD requires OOP by sharing positive experiences of doing TDD and Continuous Integration with VB6.  I'll take their word for it, but doing TDD with VB6 reminds me of seeing an elephant fly in Dumbo.  You can write almost-OO code with VB6 (minus true inheritance), but as I recall you fight against the language quite a bit.  VB6 wants to be procedural.

Let's pretend functional programming doesn't exist (because I don't know enough about it anyway) and that SOA is largely an orthogonal concept to OOP.  I'm on record as saying that a solid understanding of Object Oriented Programming is essential for succeeding with TDD on nontrivial applications.  I wouldn't hesitate to recommend TDD to someone who is new to OOP, but sooner or later that same newbie will be held back if they're not a strong OOP developer.  To defend that assertion, let's go back to some first causes:

  1. I want to be able to quickly write small unit tests that can be coded in rapid order to maintain flow
  2. External dependencies can make unit testing much more difficult and/or laborious, not to mention slower

The two primary ways to create testable code is to be religious in assigning responsibilities to different parts of your code and isolating external dependencies behind swappable interfaces.  In both cases I think OOP has a far better story than purely procedural programming.  OOP allows you to use techniques like Dependency Injection and Mock objects to replace external dependencies with fake objects that behave in a known way.  Using best OO practices leads to code that is cohesive and loose coupling, exactly the kind of code that is easier to unit test.  What can you do with procedural programming?  Function pointers?  You're certainly not going to be able to do the same kind of interaction testing we use with OOP, and that's an awfully important tool to leave behind. 

The real enabler of TDD is writing code that exposes seams to unit test in small chunks.  As long as you can accomplish that goal, you're going to be fine.  I just think that coding in an OO style gives you many more tools to create testable code.  If you can stay perfectly in the realm of state based testing and keep your functions small and relatively independent, I can see you being able to use TDD with procedural code.

Just for background, here's an older post on State vs. Interaction Testing.  You'll want to be able to do either, and know when each is most applicable.

 

P.S. I think doing TDD is actually a great way to learn OOP.  You get immediate feedback on your OO structure.


Posted 06-27-2006 5:01 PM by Jeremy D. Miller

[Advertisement]

Comments

Tomas Restrepo wrote re: So How do You Introduce TDD into an Organization or Team?
on 06-27-2006 7:45 PM
Jeremy, I won't argue with you about VB6, it was definitely a clunky beast  :)
That said, I think you're narrowing your vision of non-OOP a little bit too much if all you consider outside of it is just VB6. Frankly, I don't see why TDD wouldn't work (and indeed work very nicely) with functional and logical programming languages like haskell or prolog. At least, you can be pretty sure they are pretty well more suited to "keeping your code small and relatively independent".

Then again, it's just my very humble opinion :)
Brian Schmitt wrote re: So How do You Introduce TDD into an Organization or Team?
on 06-27-2006 9:30 PM
I am interested in TDD, (but as part of a team who unfortunately is not)
How do you proceed from there? We are a .Net shop and it seems as though all the frameworks require a reference set to the xUnit framework... How does an individual achieve this in a group setting? I feel that if I can show the value over time, I may be able to win over the rest of the team. Thanks for your help...
Jacob Eggleston wrote re: So How do You Introduce TDD into an Organization or Team?
on 06-27-2006 11:03 PM
Brian,

I can't think of any way around having a reference to your testing framework of choice. But your unit tests should probably be in a separate project anyway, so what you might do is create a separate solution which would contain your regular projects plus the unit tests.

Speaking from experience, you may end up fighting quite the uphill battle with your team, but good luck to you in your efforts.
Jacob Eggleston wrote re: So How do You Introduce TDD into an Organization or Team?
on 06-27-2006 11:09 PM
Jeremy,

It seems like your argument is more against VB6 than it is against TDD in VB6. For those poor souls who are still stuck programming in VB6, I would think that following the principles of TDD could still add value and stability to their apps.
Jeremy D. Miller wrote re: So How do You Introduce TDD into an Organization or Team?
on 06-28-2006 10:00 AM
Jacob,

I certainly agree that TDD in VB6 could add value, I just think it sounds hard.  My hats off to the folks that are making it work.  I'd just rather stay in nice easy .Net world.

Tomas,

I didn't talk about Functional languages because I don't know very much about them, other than I *really* hated working with a monotonic rules engine.  I've read a lot of people gush on about functional programming lately.  I'd really like to see some samples.

Jeremy

Jason Haley wrote Interesting Finds: June 28, 2006 AM edition
on 06-28-2006 11:20 AM
Carlton wrote re: So How do You Introduce TDD into an Organization or Team?
on 06-28-2006 2:59 PM
Brian, I might suggest checking out James Shore's "Change Diary" where he talks about "technology-first" changes and how it might be relavent to your situation.  

http://www.jamesshore.com/Change-Diary/Week-Sixteen.html

It is his experience (and mine), if you do not have developer buy-in on a technique like TDD, it will never fly.  I hope it works out for you, but I am doubtful.
Jeremy Weiskotten wrote re: So How do You Introduce TDD into an Organization or Team?
on 06-28-2006 4:08 PM
I agree: a mandate from management isn't enough to make TDD work. TDD is a culture as much as it's a programming style. Developers have to WANT to do it. I think the best way to convince others to want to do it is to first talk about it, spread an understanding of the benefits and challenges, and ultimately get people to try it (ideally in pairs). The biggest stumbling block is our natural fear of change, and the solution is education.

My company recently introduced TDD after incorporating a lot of other Agile practices over the past year. We trained about 300 developers over 6 weeks in TDD, bringing legacy code under test using some techniques from Michael Feathers' excellent book "Working Effectively with Legacy Code", and dependency injection.

The class was a mix of presentation, demonstration, Q&A, and hands-on where people paired up at workstations with Eclipse. The feedback that we got was excellent and was used to improve the class over time, and we got the sense that people really wanted to do TDD.
Brian Schmitt wrote re: So How do You Introduce TDD into an Organization or Team?
on 06-28-2006 6:34 PM
Carlton, Thanks for the link...
Jacob/Carlton,
Yes I do believe that there is a battle there, I feel that maybe the best approach may be to learn the prinicples, on projects I work on outside my employer, then once I have a firm grasp on the concepts, I may have the leverage I need to make it 'valuable' to the business....

Scott Banwart’s Blog » Blog Archive » links for 2006-06-29 wrote Scott Banwart’s Blog » Blog Archive » links for 2006-06-29
on 06-29-2006 8:22 AM
Eric Nicholson wrote re: So How do You Introduce TDD into an Organization or Team?
on 06-29-2006 8:51 AM
Speaking from experience TDD in VB6 is very hard.  I've been able to accomplish passable TDD with new development, but retrofitting existing code to bring it under test is painful.

I read through the Michael Feather's book hoping to apply some of it to VB6 and most of the techniques are impossible/impractical.  The language just puts up roadblocks at every turn.

There is definitely some benefit there, but don't expect to turn a VB6 team into true TDD believers.
JayFlowers > Changing the wheel on a moving car: Was Teaching TDD: How to approach? wrote JayFlowers > Changing the wheel on a moving car: Was Teaching TDD: How to approach?
on 06-29-2006 10:24 AM
Vikas Kerni wrote re: So How do You Introduce TDD into an Organization or Team?
on 07-02-2006 12:02 AM
Here is my roadmap for introducing TDD,CI and OOP for Legacy Systems(or Existing Systems). It is about forcing TDD and CI down the organization's throat whether organization likes it or not

http://vikasnetdev.blogspot.com/2006/06/eight-point-checks-for-servicing.html

http://vikasnetdev.blogspot.com/2006/06/what-if-we-can-maintain-our-software.html
Sam Gentile wrote New and Notable 106
on 07-06-2006 12:10 AM
I had yesterday's N&N cut short with a trip to the Jersey Shore. After a fine cookout day yesterday,...
Grant McInnes » Blog Archive » ADNUG July Meeting wrote Grant McInnes » Blog Archive » ADNUG July Meeting
on 07-11-2006 5:42 PM
Jeremy D. Miller -- The Shade Tree Developer wrote Best of the Shade Tree Developer (with actual links!)
on 08-07-2006 4:51 PM
Between being extremely short handed at work, tech' reviewing a new book, a
possible book proposal...
Grant McInnes » Blog Archive » Jeremy D. Miller — The Shade Tree Developer : So How do You Introduce TDD into an Organization or Team? wrote Grant McInnes » Blog Archive » Jeremy D. Miller — The Shade Tree Developer : So How do You Introduce TDD into an Organization or Team?
on 08-12-2006 6:19 PM
Jeremy D. Miller -- The Shade Tree Developer wrote Best of the Shade Tree Developer (with actual links!)
on 09-01-2006 2:33 PM

Between being extremely short handed at work, tech' reviewing a new book, a possible book proposal

Jeremy D. Miller -- The Shade Tree Developer wrote Jay's TDD QuickStart, and the underlying problems he stumbled into
on 03-07-2007 2:06 PM

Jay Kimble , CodeBetter's resident AJAX guru, issued a little challenge to us TDD bloggers about using

Dim Blog As New ThoughtStream(me) wrote Excellent List of TDD Starter Blog Posts
on 03-07-2007 5:05 PM

Jeremy Miller has posted quite a response to a question asked by Jay Kimble on unit testing with the...

how do i introduce myself to my new team wrote how do i introduce myself to my new team
on 06-21-2008 8:13 PM

Pingback from  how do i introduce myself to my new team

Garry Pilkington wrote Retrofitting Unit Tests
on 09-16-2008 5:55 AM

This is a post that I had written a while back and never committed to it, I think it's because the title

Add a Comment

(required)  
(optional)
(required)  
Remember Me?