Skip to content

XP Practice: Test-First Programming

February 18, 2008 by Artem

Test-First Programming (TFP) and its sometimes more known related practice Test-Driven Development(TDD)  are not very usual for the traditional software development cycle. Test-driven development simply means creating tests before writing the code they are supposed to test. A canonical test-driven cycle is as follows:

  1. Write a test for the functionality you are going to implement
  2. Write as little code as possible to make the test compile. Make sure that at this step the test fails
  3. Write minimal or almost minimal code needed to make the test pass
  4. Once the test passes, refactor the code to make it better, prettier or simpler. The test and other existing tests will guard against accidental functionality breaks during the refactoring process

Test-first programming is the extension of TDD to the whole attitude to the software development. TFP means that whenever there is a need for changing the software on any level, it is better done in the small completed chunks and every change should be accompanied with the corresponding acceptance criteria. On the code level it means test-driven development, on higher level it means working in small user stories verifiable by the acceptance tests, ideally by the executable acceptance tests.

The point of both TDD and TFP is in making the change specification being not a bloated document, but small, as concrete and visible as possible. Test-First Programming is certainly a no silver bullet in the software development, but when applied diligently is one of the most effective elements in the agile toolbox. A concrete, small and ideally executable specification is a good aid against programming by coincidence.

Links

This page is a part of the Extreme Programming overview

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <b> <i> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <br> <blockquote>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]".

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.