Main Contents

Test Driven Development Doesn’t Mean Test First?

software development, test driven development

In a post to the errata for Agile Web Development With Rails, the commenter notices that the the book barely touches on traditional TDD where you actually write the test first:

#2327: The author enters several assertions before ever trying to run the test. As this section is on TDD, it might be better to get the test to pass at the assertion of the flash. Then add the next assertion. The reader would get a better feel of the flow of tdd (write a little bit of test, see it fail, write a bit of code to make it pass, see the test pass, refactor, repeat).

Dave’s follow up is enlightening:

(Dave says: I believe this is a confusion between Test First Development and Test Driven Development. TDD doesn’t require tests to be written first)

So again the argument crops up around what Test Driven Development really is? My experience points to Kent Beck’s explanation that TDD is:

Test-Driven Development (TDD) is the powerful combination of two techniques: test-first programming, in which the programmer writes automated tests in advance of implementation, and incremental design, in which the programmer continually improves the design of the software to match the actual requirements.

Or Scott Ambler’s:

Test-driven development (TDD) (Beck 2003; Astels 2003), is an evolutionary approach to development which combines test-first development where you write a test before you write just enough production code to fulfill that test and refactoring.

Or Wikipedia:

Test-Driven Development (TDD) is a computer programming technique that involves writing test cases first and then implementing the code necessary to pass the tests.

Or Bob Martin:

The steps:

  • Write a test that specifies a tiny bit of functionality
  • Ensure the test fails (you haven’t built the functionality yet!)
  • Write only the code necessary to make the test pass
  • Refactor the code, ensuring that it has the simplest design possible for the functionality built to date

I may have missed a memo somewhere, but TDD doesn’t compromise on test first. I think the only confusion is that the name Test Driven Development isn’t as clear as something like Test First Development or Test First Design. Of course we seem to be headed towards approaches like Dave Astel’s Behavior Driven Development to help alleviate any confusion like this.

Ed Gibbs @ April 18, 2006

4 Comments

  1. keith ray April 19, 2006 @ 5:38 am

    A common confusion is thinking that TFD means writing ALL the tests first.

    And some practitioners of TDD prefer to have only one assertion per test, and thus really small and focused tests.

  2. Dave Nicolette April 19, 2006 @ 9:29 am

    I think you’re right that present-day agile practice assumes TDD means write the tests first. As Keith points out, that doesn’t mean to write all the tests first.

    There’s a continuing evolution in development practices. If I understand correctly, the idea of TDD has its roots in XP, in which the original concept was to make sure anything that might break was thoroughly tested before delivering the code. I think the term TDD was coined before it became common practice to write tests first.

    At some point, someone realized that by writing the unit test cases before the code to be tested, they could have what amounted to an executable coding specification. Since then, people have been extending the idea to higher levels of abstraction (or larger scopes, if you prefer) - integration, functional, “story” tests, etc.

    There’s also the notion of behavior-driven development (BDD), which seems to be mainly a semantical device to steer people’s thinking away from “testing” and make this style of work more explicitly and obviously a development practice.

    With that sort of ongoing improvement happening, I wouldn’t look for any sort of static definition that will remain valid for long. The idea that TDD doesn’t necessarily require tests to be written first was perfectly valid two or three years ago, which is probably why you can still find quotations here and there distinguishing between TDD and TFD. The Bob Martin quote you posted represents the current standard of practice.

  3. Tim April 19, 2006 @ 12:29 pm

    Dave Thomas goes into further detail in this post (http://blogs.pragprog.com/cgi-bin/pragdave.cgi/Practices/TestDrivenOrTestFirst.rdoc) from about two years ago.

  4. Ed Gibbs April 24, 2006 @ 6:10 pm

    Good catch on Dave explaining his ideas around TDD versus TFD. I figured his thinking was along this route, it just doesn’t gel too well with current practice.

    Again I think the point is well taken that the current state of the art with writing tests or specs against your code continues to evolve as people put the ideas into practice.

Leave a comment


Feed