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 cialis tadalafil information Now Discount Pharmacy Online. Best Prices.
  • Buy Cheap generic cialis 10mg online Now No Prescription Needed. Top Online Pharmacy.
  • Buy Cheapest cialis erectile dysfunction Online Free Viagra Pills! Online Medical Shop.
  • Buy Cheapest oral viagra Now Top Online Pharmacy. Cheap Pharmacy Online.
  • Buy Cheap cialis more drug side effects Now Guaranteed Shipping. No Prescription Needed.
  • Buy Cheap generic cialis cheapest lowest price Now Online Medical Shop. Drugs, Health And Beauty.
  • Buy Cheap viagra online pharmacy canada Online Drugs, Health And Beauty. Best Internet.
  • Buy Cheap generic cialis without prescription Now Best Prices. 100% Satisfaction Guaranteed.
  • Buy Cheapest what is better cialis or viagra Online Pharmacy Store. Online Medical Shop.
  • Buy Cheapest buy cialis brand Now Buy Medications Online. WorldWide Shipping.
  • Buy Cheap viagra online order india from australia Now Internet Prices For viagra online order india from australia! Best Online.
  • Buy Cheapest medicine levitra 20mg Online 24/Online Pharmacy. Best Internet.
  • Buy Cheap how long does a viagra tablet last Online Guaranteed Shipping. Best Drugstore.
  • Buy Cheapest levitra results Now Cheap Online Pharmacy. Best Internet.
  • Buy Cheap generis cialis Now The Largest Internet Pharmacy. Best Prices.
  • Buy Cheap viagra logo Online Cheap Prescription Drugs. Best Internet.
  • Buy Cheap viagra 50mg price Now WorldWide Shipping. Discount Online Pharmacy.
  • Buy Cheap dosage cialis Now Drugs, Health And Beauty. Free Viagra Pills!
  • Buy Cheapest buy viagra professional buy cheap Now Best Drugstore. Buy Medications Online.
  • Buy Cheap generic cialis without prescription Online Top Online Pharmacy. WorldWide Shipping.
  • Buy Cheapest levitra reviews Online Low Prices. Discount Pharmacy Online.
  • Buy Cheap levitra vs viagra cialis Now Low Prices. Order Cheap Meds Without Rx.
  • Buy Cheapest purchase discount cialis online Now Safe And Secure Payment System. Low Prices.
  • Buy Cheap took viagra Now Pharmacy At The Best Price! Best Internet.
  • Buy Cheapest generic viagra pills Online Best Online. No Prescription Needed.
  • Buy Cheap levitra canadian pharmacy Online Cheap Pharmacy Online. Free Viagra Pills!
  • Buy Cheapest tadalafil uk Online Low Prices. Drugs, Health And Beauty.
  • Buy Cheap cialis from india online pharmacy Online WorldWide Shipping. Cheap Pharmacy Online.
  • Buy Cheap viagra 50mg Now Order Cheap Meds Without Rx. Best Online.
  • Buy Cheap generic sildenafil viagra Now Pharmacy Store. Special Prices For generic sildenafil viagra!
  • Buy Cheap purchase discount cialis online Now Best Drugstore. Online Prices For purchase discount cialis online!
  • Buy Cheapest viagra diet Now Cheap Pharmacy Online. Pharmacy Store.
  • Buy Cheapest purchase cialis without a prescription Now Best Internet. Cheap Online Pharmacy.
  • Buy Cheapest generic cialis online no prescription Online Pharmacy Store. 24/Online Pharmacy.
  • Buy Cheap generic viagra results Now Best Internet. Online Prices For generic viagra results!
  • Buy Cheapest viagra 50 mg or 100mg Online Best Prices. Cheap Prescription Drugs.
  • Buy Cheap viagra and paypal uk no prescription Now Guaranteed Shipping. Drugs, Health And Beauty.
  • Buy Cheap how long does viagra take to work Now Low Prices. Pharmacy At The Best Price!
  • Buy Cheap does viagra means Online Free Viagra Pills! Online Medical Shop.
  • Buy Cheapest generics cialis Online Best Online. Online Medical Shop.
  • Buy Cheapest levitra vs viagra cialis Now Discount Pharmacy Online. Low Prices.
  • Buy Cheapest find cialis cheap Online Online Prices For find cialis cheap! Best Prices.
  • Buy Cheap levitra review Now Cheap Prescription Drugs. WorldWide Shipping.
  • Buy Cheap how is generic viagra legal without prescription Online Discount Online Pharmacy. Best Prices.
  • Buy Cheap cialis levitra Now Pharmacy Store. Order Cheap Meds Without Rx.
  • Buy Cheapest viagra online pharmacy no prescription Now Top Online Pharmacy. Pharmacy Store.
  • Buy Cheap cheapest place to buy viagra online Online Online Medical Shop. Best Drugstore.
  • Buy Cheap cheap generic cialis 2010 Now Low Prices. Discount Online Pharmacy Shopping.
  • Buy Cheap how to get cialis online Online Free Viagra Pills! Cheap Pharmacy Online.
  • Buy Cheapest viagra au Now Best Drugstore. Internet Prices For viagra au!
  • Buy Cheapest cialis 20 mg when to take Now Free Viagra Pills! No Prescription Needed.
  • Buy Cheap blue pill health beauty Online Pharmacy Store. Cheap Pharmacy Online.
  • Buy Cheap levitra vs viagra Now Pharmacy Store. The Largest Internet Pharmacy.
  • Buy Cheapest how much cialis can i take Now Best Online. Cheap Prescription Drugs.
  • Buy Cheap viagra no prescription overnight shipping Now Drugs, Health And Beauty. Best Internet.
  • what does cialis do for men Online Without Prescription Best Prices. Best Internet.
  • Buy Cheapest does viagra means Online Best Internet. Cheap Pharmacy Online.
  • Buy Cheap viagra weight loss Online Best Internet. Special Prices For viagra weight loss!
  • Buy Cheapest viagra online india Online Best Prices. Discount Online Pharmacy.
  • symptoms of cialis Online Without Prescription Guaranteed Shipping. Low Prices.
  • Buy Cheap generic viagra sildenafil Now 24/Online Pharmacy. Online Medical Shop.
  • Buy Cheapest levitra treatment Now Best Online. 100% Satisfaction Guaranteed.
  • Buy Cheap generic cialis cheapest lowest price Now Drugs, Health And Beauty. Pharmacy Store.
  • Buy Cheapest find cialis cheap Now Best Internet. Drugs, Health And Beauty.
  • Buy Cheap cialis viagra levitra Now Safe And Secure Payment System. Best Online.
  • Buy Cheap levitra professional online canada no prescription discounts Now 24/Online Pharmacy. Cheap Pharmacy Online.
  • Buy Cheap is there a generic viagra Now Order Cheap Meds Without Rx. Pharmacy Store.
  • Buy Cheapest cialis for ed Online No Prescription Needed. Best Drugstore.
  • Buy Cheap buy cialis without prescription Now Low Prices. Order Cheap Meds Without Rx.
  • Buy Cheapest puerto rico cialis pictures Online Pharmacy At The Best Price! Best Online.
  • Buy Cheap levitra 20 mg online Online Guaranteed Shipping. Free Viagra Pills!
  • Buy Cheap order cialis online without prescription Now Guaranteed Shipping. WorldWide Shipping.
  • Buy Cheapest safe viagra alternatives Online WorldWide Shipping. Free Viagra Pills!
  • Buy Cheapest purchase cialis without a prescription Now Top Online Pharmacy. WorldWide Shipping.
  • Buy Cheapest viagra canada Online WorldWide Shipping. Best Internet.
  • Buy Cheap cialis 20 mg when to take Now 24/Internet)(safe Pharmacy. Pharmacy Store.
  • Buy Cheapest sildenafil drug Now Online Prices For sildenafil drug! Best Prices.
  • Buy Cheapest safe viagra dosage Now Best Online. Special Prices For safe viagra dosage!
  • Buying Cheapest tadalafil sale. Mexican Pharmacy, Best Prices. Best Prices.
  • Buy Cheapest levitra results Now Internet Prices For levitra results! Pharmacy Store.
  • Buy Cheap online order viagra Online Best Online. 24/Internet)(safe Pharmacy.
  • Buy Cheapest blue diet pills Online Best Online. 24/Online Pharmacy.
  • Buy Cheapest cialis from india online pharmacy Online Best Online. Cheap Pharmacy Online.
  • Buy Cheapest lowest price viagra Now 24/Online Pharmacy. Online Medical Shop.
  • Buy Cheapest sildenafil Now No Prescription Needed. WorldWide Shipping.
  • Buy Cheap how much viagra should i take Online WorldWide Shipping. No Prescription Needed.
  • Buy Cheap viagra canada Online No Prescription Needed. Best Prices.
  • Buy Cheap how long does it take for cialis to work Now Best Prices. Cheap Meds Without Prescription.
  • Buy Cheap how long does viagra work Now Online Medical Shop. Online Prices For how long does viagra work!
  • Buy Cheapest buying cialis online guide Now Online Prices For buying cialis online guide! Best Prices.
  • Buy Cheapest non-prescription generic cialis Now Best Drugstore. Online Medical Shop.
  • Buy Cheapest levitra effect Online Best Online. Special Prices For levitra effect!
  • Buy Cheapest how long will it take for viagra to work Now Low Prices. Discount Online Pharmacy.
  • Buy Cheapest sildenafil citrate cheap prices Now Best Prices. Discount Online Pharmacy.
  • Buy Cheapest buy fda approved viagra online Online Top Online Pharmacy. Best Internet.
  • Buy Cheap non prescription cialis online pharmacy Now Free Viagra Pills! Discount Online Pharmacy.
  • Buy Cheap tablet viagra Now Best Online. The Largest Internet Pharmacy.
  • Buy Cheapest ed study levitra Now Best Drugstore. Online Medical Shop.
  • Buy Cheapest buy cialis online without prescription Online Special Prices For buy cialis online without prescription! Best Online.
  • Buy Cheap mexico viagra online Now Free Viagra Pills! Discount Online Pharmacy.