Erasing history in tests

Something I say about the ideal of Agile design is that, at any moment when you might ship the system, the code should look as if someone clever had designed a solution tailored to do exactly what the system does, and then implemented that design. The history of how the system actually got that way should be lost.

An equivalent ideal for TDD might be that the set of tests for an interoperating set of classes would be an ideal description-by-example of what they do, of what their behavior is. For tests to be documentation, the tests would have to be organized to suit the needs of a learner (most likely from simple to complex, with error cases deferred, and - for code of any size - probably organized thematically somehow).

That is, the tests would have to be more than what you’d expect from a history of writing them, creating the code, rewriting tests and adding new ones as new goals came into view, and so forth. They shouldn’t be a palimpsest with some sort random dump of tests at the top and the history of old tests showing through. (”Why are these three tests like this?” “Because when behavior X came along, they were tests that needed to be changed and it was easiest to just tweak them into shape.”)

I’ve seen enough to be convinced that, surprisingly, Agile design works as described in the first paragraph, and that it doesn’t require superhuman skill. The tests I see - and write - remind me more of the third paragraph than the second. What am I missing that makes true tests-as-documentation as likely as emergent design is?

(It’s possible that I demand too much from my documentation.)

9 Responses to “Erasing history in tests”

  1. Michal Migurski Says:

    Aaron Cope from Flickr has a way of talking about documentation that roughly maps here: the documentation should be a story about the code, showing how it’s used and more importantly why. It should begin at the beginning and end and the end, and help the user follow a thread through the features rather than present a simple core dump of method parameters descriptions.

    I love this idea of putting the code into a coherent narrative.

    Python has a package called doctest that implements this in a lovely way, where you start off a module with a textual description of how it’s used in the form of annotated code examples. If you do them right, they can be parsed, run, and verified by doctest in the form of a unit test. It’s quite awesome.

  2. Clarke Ching Says:

    I’ve no idea what the answer to your question is, Brian, but I love that you’ve asked the question.

  3. John Sumsion Says:

    I recently had a valuable experience watching new members of my team grapple with tests of the 3rd paragraph variety.

    We used the expressions of disbelief and confusion as hints for how we could simplify the code. We created simpler tests that were easier to properly organize and have started removing the disorganized and overly-complex tests.

    In short, it is important to listen to a new person’s first impressions of a test and organize and rewrite until it seems obvious. Make the test suite discoverable.

  4. Brian Marick Says:

    When you say that you “simplified the code”, do you mean test code, or were there effects on the product code?

  5. John Sumsion Says:

    The production code was too complex and needed to be broken into pieces. The new tests for those pieces were straightforward to write and easy to understand without a lot of history.

    The existing test suite basically contained a lot of integration tests, where the real purpose of each test was buried inside some assertEquals() without a “why” comment, or worse in some kind of assertTrue() three call levels away from the test…() method.

    Some of these complex tests were redundant and were removed. Some were so complicated that it was more work to remove them than we had time for. I want to get better at looking at a test suite (in a macro view, a la Edward Tufte) and cutting it down to the bare minimum.

    My point is that it is a Good Thing to have a low tolerance for artificial complexity — and the new members of a team usually bring that along with them.

  6. Michael Bolton Says:

    What am I missing that makes true tests-as-documentation as likely as emergent design is?

    I’m not sure I understand the question. Do you mean to ask, “What would increase the likelihood that our tests would provide all the documentation that (some person) needed?”, or some other question?

  7. Brian Marick Says:

    Michael: I mean that, in coding, we have one thing - a design, and a good one - that emerges out of a seemingly unrelated activity (making the next test pass). Design comes about as a reliable-enough side effect of TDD. It doesn’t seem to me that good documentation falls out in the same way. It seems odd to ask “why not?” - a more sensible question might be “Why should it?” - but that’s what I’m asking.

  8. Michael Bolton Says:

    >I mean that, in coding, we have one thing - a design, and a good one - that emerges out of a seemingly unrelated activity (making the next test pass).

    I’m interested in probing these ideas. I’m still not sure whether you’re suggesting that TDD should lead to good documentation, or that good documentation should lead to good products. However…

    0) I genuinely believe that it’s more helpful to follow your example and use the word “example” instead of “test” in this context.

    1) Does a design emerge from making the examples pass, or is making each example pass simply a conceit, an alias, for asking (and answering) the next question about the design?

    2) Is what we see necessarily a good design, considering that good is always asked “compared to what?” Could it be a good design with respect to the questions that that the product has been programmed to answer, but a crappy design with respect to other questions that haven’t been asked yet? Could it be both at the same time?

    3) Is making the next example pass really an unrelated activity to design? (I’ll answer for myself that I see a pretty strong relationship.) Is design really a side-effect of TDD, or is it the direct intention of TDD?

    4) If we construct something by a process of saying, “it should do this… and then this… and then this… and then this…”, and the “this”s are sufficient numerous general, AND we’ve eliminated a bunch of cases in which it didn’t do what we wanted it to, could it look designed without actually being designed? Consider the human eyeball as an example.

    5) I see documentation as someone’s stories about a product. That includes a set of assertions about what the product can do–examples sometimes provide those well enough. But good documentation also tends to include some suggestions about the context for using the product, some warnings about what not to do with it, ideas about the human’s potential relationships with the product. These are in the form of narratives, not simply true-or-false assertions that can be checked by a pretty dumb machine. So I’m unsurprised that TDD-style examples don’t lead to these stories; they tend not to be motivated much by Why? and Who?

    —Michael B.

  9. Brian Marick Says:

    1) Does a design emerge from making the examples pass, or is making each example pass simply a conceit, an alias, for asking (and answering) the next question about the design?

    To me, the design seems to emerge mostly from the refactoring after you make the test pass.

    2) Is what we see necessarily a good design, considering that good is always asked “compared to what?” Could it be a good design with respect to the questions that that the product has been programmed to answer, but a crappy design with respect to other questions that haven’t been asked yet? Could it be both at the same time?

    To my mind, a good design is one that makes the next unanticipated change easy. “Easy” is compared to some historical average of code I’ve worked with.

    3) Is making the next example pass really an unrelated activity to design? (I’ll answer for myself that I see a pretty strong relationship.) Is design really a side-effect of TDD, or is it the direct intention of TDD?

    I don’t know how to answer that question. Certainly, now that people emphasize the “design” in TDD more than the “test”, they can’t willfully not think of design issues. (”Don’t think of an elephant.”) But design happens at different scales. What’s surprising about TDD is that working at a small-scale seems often to yield better-designed larger-scale structures. I think.

    4) If we construct something by a process of saying, “it should do this… and then this… and then this… and then this…”, and the “this”s are sufficient numerous general, AND we’ve eliminated a bunch of cases in which it didn’t do what we wanted it to, could it look designed without actually being designed? Consider the human eyeball as an example.

    Dunno. How would my future actions differ if I believed that something “was designed” vs “looks designed”?

    5) I see documentation as someone’s stories about a product. That includes a set of assertions about what the product can do–examples sometimes provide those well enough. But good documentation also tends to include some suggestions about the context for using the product, some warnings about what not to do with it, ideas about the human’s potential relationships with the product. These are in the form of narratives, not simply true-or-false assertions that can be checked by a pretty dumb machine. So I’m unsurprised that TDD-style examples don’t lead to these stories; they tend not to be motivated much by Why? and Who?

    Sure they’re motivated by “Why?” and “Who?”. Who is the person writing the test and code, right this instant. Why is in support of some other code you can point at right now. What’s interesting about TDD is that you can achieve good design (by my lights) with such selfishly limited answers.

    The context is the context possessed by the person doing the work. In a well-functioning, long-lived team, that context is shared by all the programmers. (Remember: we’re talking about unit-ish tests here.) [The difference between TDD for teams vs. TDD for open source needs to be talked about more, since a big difference is in how easily context is shared.] So there are questions like: shared enough? what reminders need to be planted somewhere a programmer will notice them, and which can go without saying? The goal would be to write the minimal amount needed for the audience. I don’t know what that amount is, but when I’m the audience - and the producer - I feel like the minimum amount isn’t being written. Or that what is being written isn’t a superset of the minimum amount - too much is extraneous, not a help, a waste.

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.