Resumen y Enlaces

En resumen:

  1. Think: Figure out what test will best move your code towards completion. (Take as much time as you need. This is the hardest step for beginners.)

  2. Red: Write a very small amount of test code. Only a few lines... usually no more than five. Run the tests and watch the new test fail: the test bar should turn red. (This should only take about 30 seconds.)

  3. Green: Write a very small amount of production code. Again, usually no more than five lines of code. Don't worry about design purity or conceptual elegance.

    Sometimes you can just hardcode the answer. This is okay because you'll be refactoring in a moment.

    Run the tests and watch them pass: the test bar will turn green. (This should only take about 30 seconds, too.)

  4. Refactor: Now that your tests are passing, you can make changes without worrying about breaking anything.

    1. Pause for a moment. Take a deep breath if you need to.
    2. Then look at the code you've written, and ask yourself if you can improve it.
    3. Look for duplication and other "code smells."
    4. If you see something that doesn't look right, but you're not sure how to fix it, that's okay.
    5. Take a look at it again after you've gone through the cycle a few more times. (Take as much time as you need on this step.)
    6. After each little refactoring, run the tests and make sure they still pass.

  5. Repeat: Do it again. You'll repeat this cycle dozens of times in an hour. Typically, you'll run through several cycles (three to five) very quickly, then find yourself slowing down and spending more time on refactoring. Than you'll speed up again. 20-40 cycles in an hour is not unreasonable.

James Shore, The Art of Agile Programming


Casiano Rodriguez León 2015-01-07