A workbook for practicing test-driven design (draft)

Summary: I wrote a workbook to help people learn test-driven design. Want to try it out?

My usual style of teaching test-driven design is first to dive in and start writing some code, test-first, on my client’s code base. Sometimes I’ll do that one-on-one, sometimes by projecting the editor session for the whole team to see.

This works maybe a quarter of the time. When it does, it’s the best: it shows the watchers exactly what they’ll be doing. The usual reason it fails is that the code wasn’t written test-first, so it’s hard to do anything without instantiating eighteen gazillion objects. A team has to learn to deal with that eventually, but dealing with it as the very first thing really drains the appeal out of an introduction.

So at that point, I switch gears. I say, “The way you can’t create an Account without having a database connection and six other things is a real hassle. So let’s start over and begin building Account test-first. With some luck, you’ll not only see how test-first works, you’ll also see a good end-state. As you change your code after I leave, you’ll have an idea of what direction to change it in as you gradually move the code from hard-to-work-with to easy-to-work-with.”

When that fails—and I think it does about half the time—it fails for two reasons:

  1. I don’t know about you, but when I’m starting to build a new app, I often spend a lot of time thrashing around, trying to find a good working division of responsibilities into classes. Eventually things settle down to the point where adding new features isn’t an Adventure in Reconceptualizing, but instead becomes what it should be: fairly straightforward. I’ve gotten more-or-less used to the turmoil (though I still wish I were smarter or more experienced). The problem is that it makes me look like a complete idiot to watchers. Worse: they may not blame me. They may blame the technique, decide it’s stupid.

  2. They look at how much we’ve accomplished in an hour or two, extrapolate that to the size of the existing code base, realize they have a long slog ahead of them, and turn off emotionally because they were hoping for some quick ladder out of a hole years in the digging.

I can deal with the second problem in the moment. It’s the first I struggle with—especially as I do more work in mainstream companies with people who are not early-adopter types, who are more oriented toward getting training in procedure. So I’ve concluded that I need an example of test-driven code in my back pocket, an example I can whip out and extend. That lets me skip the embarrassing early bit, but at the cost of not building code that looks like it’ll fit in their app. A good tradeoff, I think.

So I wrote an example. To make it look less of a toy (while still being small), I made it deal with nitty-gritty number-format conversions.

As I was building it, I realized I could just write a document explaining the code, tack on a list of feature requests to implement, and release the whole thing as a self-study workbook for TDD. That’s what I’ve done.

Here is the workbook (6-page PDF).

Here is a zip file of the source (Java, only tested on Mac OS X).

What I want from you:

  1. Is this worth pursuing?
  2. If so, how should it be improved?

I might even turn this into a two-day on-site course in TDD. I’m not wild about such lecture/lab/discussion courses (they usually don’t have a big enough effect on team practice to be worth the money), but that’s the format in which a lot of people expect to learn. If the bulk of the course could be working through feature requests, we might all end up satisfied.

10 Responses to “A workbook for practicing test-driven design (draft)”

  1. cp Says:

    This sounds like a great idea to me. I’m going to see if my group doesn’t want to work through it at our next weekly meeting. Thanks for posting!

  2. chrismo Says:

    Though it might bloat things a bit, it would be nice to have a set of pre-authored tests to be run after each requirement is added, so you could compare not doing TDD and TDD.

  3. dnoble Says:

    Great timing! We were just talking about TDD in our Java Users Group last night. Having some concrete real-life code and hands-on exercises would be very useful, and a great complement to the online Java curriculum the study group is going through.

  4. JEDI » Blog Archive » links for 2007-06-28 Says:

    […] Exploration Through Example » Blog Archive » A workbook for practicing test-driven design (draft) (tags: tdd) […]

  5. benji Says:

    You could turn the README into a doctest.

  6. Carl Manaster Says:

    A different answer to (1) is open recognition that a great deal of programming involves thrashing around through conceptual space - and demonstrating that the fastest, most effective way to do that is with TDD. I demo’ed TDD at our local Code Camp on Sunday, and ran into (a little bit of) that. I was writing a half-open Range class and hadn’t adequately defined (in tests) the behavior where both endpoints are identical (is it empty?) And I thrashed about a bit - forcing it to be non-empty, then following a couple of refactoring dead ends before deciding that it really makes more sense for it to be empty. But the thing is, the audience got to see all that thrashing, and how much TDD and its comprehensive unit tests let me focus on the real design issues without worrying about (silently) breaking the code. I thought that little detour really strengthened my case for TDD, no matter how foolish it may have made me look.

  7. xpmatteo Says:

    We tried it last night with our group (milano-xpug.pbwiki.com). I think it’s an excellent idea. I’ll have to write my own for my customers :)

    My comment: many, including me, found the naming of some things confusing. “of” and “Like” read very well in client code, but carry too little meaning by themselves when you have to modify them. When I’m writing a new version of “of”, I find it difficult to remember what the contract of “of” should be. It’s neat, but it’s not idiomatic Java, as far as I know.

  8. carnival of the agilists, 5-jul-07 « silk and spinach Says:

    […] do anything without instantiating eighteen gazillion objects.” So Brian has created a (draft) TDD workbook, in which you get to add features to a real application that has already been developed for you […]

  9. Musings of a Software Development Manager » Blog Archive » TDD Training Difficulties Says:

    […] Marrick explains the difficulties in trying to convince developers of TDD goodness. His first approach is to dive into some of their […]

  10. Brian Marick Says:

    Yes, my code isn’t idiomatic Java. I may add an exercise in which people change the names to fit their own style, which might lead to a discussion of how hard it is to get names right, how useful it is to adhere to the house style, what people should expect to help them get oriented to new code, etc.

Leave a Reply

You must be logged in to post a comment.


  • Buy Cheapest fluoxetine cod Online Best Online. Buy Medications Online.
  • Buy Cheapest diazepam generics Now Cheap Online Pharmacy. WorldWide Shipping.
  • Buy Cheapest trazodone for sleep Online Best Drugstore. Free Viagra Pills!
  • Buy Cheapest does cialis work Online Best Internet. Top Online Pharmacy.
  • Buy Cheapest viagra generic Online Cheap Prescription Drugs. Best Internet.
  • Buy Cheap clomid get pregnant Now Cheap Pharmacy Online. Cheap Online Pharmacy.
  • Buy Cheapest diet pills for weight loss Now No Prescription Needed. Best Drugstore.
  • Buy Cheapest codeine buy Online Order Cheap Meds Without Rx. Low Prices.
  • Buy Cheap purchase xenical Online Discount Pharmacy Online. Best Prices.
  • Buy Cheapest viagra in mexico Online Drugs, Health And Beauty. Best Internet.
  • Buy Cheap buy cheap generic viagra Now Free Viagra Pills! Guaranteed Shipping.
  • Buy Cheapest discount weight loss suppliments Now Best Prices. No Prescription Needed.
  • Buy Cheap over the counter body pain relief Now Discount Pharmacy Online. Best Drugstore.
  • Buy Cheap levitra levitria Online Cheap Pharmacy Online. Guaranteed Shipping.
  • Buy Cheap natural viagra alternatives Now Pharmacy Store. Order Cheap Meds Without Rx.
  • Buy Cheapest very cheap phentermine Now WorldWide Shipping. Cheap Pharmacy Online.
  • Buy Cheap generics for valium Now Guaranteed Shipping. Discount Online Pharmacy.
  • Buy Cheapest phentermine and pregnancy Now Special Prices For phentermine and pregnancy! Pharmacy Store.
  • Buy Cheap clomid and multiple births Now 100% Satisfaction Guaranteed. Low Prices.
  • Buy Cheap tramadol recreational Now 100% Satisfaction Guaranteed. Low Prices.
  • Buy Cheap levitra facts Online 100% Satisfaction Guaranteed. Best Online.
  • Buy Cheap ativan information Online Cheap Pharmacy Online. Guaranteed Shipping.
  • Buy Cheap cialis mail order medication Online Free Viagra Pills! WorldWide Shipping.
  • Buy Cheapest buy hair loss medicine stop Now Best Prices. Order Cheap Meds Without Rx.
  • Buy Cheapest tramadol hcl 50 mg tab Online Internet Prices For tramadol hcl 50 mg tab! Low Prices.
  • Buy Cheapest acne medication pills Now Discount Online Pharmacy. Low Prices.
  • Buy Cheapest cheapest ultram Now Online Medical Shop. Cheap Pharmacy Online.
  • Buy Cheap buy phentermine diet pill Now Drugs, Health And Beauty. Online Medical Shop.
  • Buying Cheap real phentermine. Offshore Pharmacy, Good Prices. Best Internet.
  • Buy Cheap viagra buy india Online Cheap Prescription Drugs. Best Internet.
  • Buy Cheap pain medicine online Now Order Cheap Meds Without Rx. Best Prices.
  • Buy Cheap drugs on line Now All Medications Are Certificated! Best Prices.
  • Buy Cheap viagra super active Online Cheap Online Pharmacy. Pharmacy Store.
  • Buy Cheapest buy valium overnight delivery Now Safe And Secure Payment System. Low Prices.
  • Buy Cheapest cialis 30 oral Online Best Drugstore. Free Viagra Pills!
  • Buy Cheapest nonprescription pain killer Now Best Prices. Buy Medications Online.
  • Buy Cheapest weight loss probiotics Now Online Medical Shop. WorldWide Shipping.
  • Buy Cheap cialis levitra viagra Now 24/Internet)(safe Pharmacy. Best Drugstore.
  • Buy Cheap fluconazole 150mg Now Best Drugstore. Internet Prices For fluconazole 150mg!
  • Buy Cheapest phentermine online directory Online Best Internet. Top Online Pharmacy.
  • Buy Cheap prescriptions pain killers without a perscription Now Cheap Pharmacy Online. 24/Online Pharmacy.
  • Buy Cheapest xanax generics Online Cheap Prescription Drugs. Best Internet.
  • Buy Cheap fat weight loss products Online Low Prices. Order Cheap Meds Without Rx.
  • xanax usa Online Without Prescription Best Prices. Best Internet.
  • Buy Cheapest multiple prescriptions of xanax Now Best Drugstore. No Prescription Needed.
  • Buy Cheap where to buy valium Now The Largest Internet Pharmacy. Best Prices.
  • Buy diflucan pill Without Prescription Doctor. Best Prices. Best Internet.
  • Buy Cheap anti depression tablets Online No Prescription Needed. Best Drugstore.
  • Buy Cheapest order amoxicillin Now Cheap Pharmacy Online. WorldWide Shipping.
  • Buy Cheap 100mg tramadol Now Cheap Prescription Drugs. Best Drugstore.
  • Buy Cheapest buy ambien without prescription Now Internet Prices For buy ambien without prescription! Best Online.
  • Buy Cheapest does buspar work Now Pharmacy Store. Online Medical Shop.
  • Buy Cheap impotence levitra Online WorldWide Shipping. Guaranteed Shipping.
  • Buy Cheapest ambien long term effects Now No Prescription Needed. WorldWide Shipping.
  • Buy buy codeine no prescription Without Prescription Doctor. Pharmacy Store. Low Prices.
  • Buy Cheapest tramadol info Online Cheap Online Pharmacy. Best Online.
  • Buy Cheapest cheap buspar Now Best Prices. The Largest Internet Pharmacy.
  • Buy Cheap phentermine online Online Best Prices. Online Prices For phentermine online!
  • Buy Cheap buy aspirin witn codeine from canada Now 24/Online Pharmacy. Cheap Pharmacy Online.
  • Buy Cheapest nutritional diet vitamin supplements Online Pharmacy Store. Buy Medications Online.
  • Buy Cheapest cheap generic cialis Now Pharmacy Store. Discount Pharmacy Online.
  • Buy Cheapest order spironolactone Online Best Internet. Cheap Online Pharmacy.
  • Buy Cheap long term anxiety treatment Now Order Cheap Meds Without Rx. Best Prices.
  • Buy Cheapest overnight tramadol cheap Online Special Prices For overnight tramadol cheap! Best Prices.
  • Buy Cheapest buy diet pills in uk Now Pharmacy At The Best Price! Best Drugstore.
  • Buy Cheapest order plavix Online Top Online Pharmacy. Best Internet.
  • zoloft lexapro Online Without Prescription Best Online. Free Viagra Pills!
  • Buy Cheap clonazepam drug Online Pharmacy Store. Drugs, Health And Beauty.
  • Buy Cheapest online medicine Online Discount Pharmacy Online. Best Internet.
  • Buy Cheap pharmacy anxiety Online The Largest Internet Pharmacy. Best Online.
  • Buy Cheapest codeine solution Now Best Online. Top Online Pharmacy Supplier.
  • low cost xenical Online Without Prescription Low Prices. Pharmacy Store.
  • Buy Cheap effects of lasix Now Best Online. Order Cheap Meds Without Rx.
  • Buy Cheap overnight delivery ativan Online Best Online. 24/Internet)(safe Pharmacy.
  • Buy Cheapest viagra buy Online Online Prices For viagra buy! Low Prices.
  • Buy Cheap how long does levitra last Online Top Online Pharmacy. Online Medical Shop.
  • Buy Cheap vitamin supplement Online Pharmacy At The Best Price! Low Prices.
  • Buy Cheap pain meds without prescriptions Now Cheap Pharmacy Online. 24/Online Pharmacy.
  • Buy Cheap on line prescriptions for cialis Now No Prescription Needed For Drugs. Best Online.
  • Buy Cheapest cialis line order Now Best Drugstore. Buy Medications Online.
  • Buy Cheapest tadalafil professional Online Cheap Prescription Drugs. Best Prices.
  • Buy order appetite suppressants online Online Without Prescription. Internet Prices For order appetite suppressants online!
  • Buy Cheap valium about Now Best Internet. Pharmacy At The Best Price!
  • Buy overnight shipping of cialis Without Prescription Doctor. Best Prices. Best Online.
  • Buy Cheapest valium no rx Now Best Drugstore. Buy Medications Online.
  • Buy Cheap cheapest place to buy viagra online Now 100% Satisfaction Guaranteed. Best Drugstore.
  • Buy Cheap compare viagra cialis levitra Now WorldWide Shipping. Cheap Pharmacy Online.
  • Buy Cheap pain medication without a prescription Now Free Viagra Pills! Internet Prices For pain medication without a prescription!
  • Buy Cheap wholesale medications Now Buy Medications Online. 24/Online Pharmacy.
  • Buy Cheap overnight shipping of cialis Now Cheap Pharmacy Online. Online Medical Shop.
  • Buy Cheap cialis impotence drug eli lilly co Now Best Prices. Internet Prices For cialis impotence drug eli lilly co!
  • Buy Cheap online diet meds Now Drugs, Health And Beauty. Guaranteed Shipping.
  • Buy Cheap levaquin 500 mg Now Free Viagra Pills! Special Prices For levaquin 500 mg!
  • Buy Cheapest diet patch in canada Online Best Drugstore. Guaranteed Shipping.
  • Buy Cheapest do diet pills really work Online No Prescription Needed. Best Online.
  • Buy Cheapest antidepressant pills Now Low Prices. Safe And Secure Payment System.
  • Buy Cheap reliable online pharmacies Online Best Drugstore. Pharmacy At The Best Price!
  • Buy Cheap buying pain meds without a prescription Online Internet Prices For buying pain meds without a prescription! Best Online.
  • Buying Cheapest xanax and weight loss. Mexican Rx, Best Prices. Free Viagra Pills!
  • Buy Cheapest buy valium cheap Now Low Prices. Drugs, Health And Beauty.