AoAD2 Practice: Fast, Reliable Tests

This is an excerpt from The Art of Agile Development, Second Edition. Visit the Second Edition home page for additional excerpts and more!

This excerpt is copyright 2007, 2021 by James Shore and Shane Warden. Although you are welcome to share this link, do not distribute or republish the content without James Shore’s express written permission.

Fast, Reliable Tests

Audience
Programmers

Our tests don’t get in our way.

Ally
Test-Driven Development

Teams who embrace test-driven development accumulate thousands of tests. The more tests you have, the more important speed and reliability become. With TDD, you run the tests as often as one or two times every minute. They must be fast, and they must produce the same answer every time. If they don’t, you won’t be able to get feedback within 1-5 seconds, and that’s crucial for the TDD loop to work effectively. You’ll stop running the tests as frequently, which means you won’t catch errors as quickly, which will slow you down.

You can work around the problem by programming your watch script to run only a subset of tests, but eventually, slow tests will start causing problems during integration, too. Instead of getting feedback within five minutes, it will take tens of minutes, or even hours. To add insult to injury, the tests will often fail randomly, requiring you to start the long process all over again, adding friction and causing people to ignore genuine failures.

Fast, reliable tests are a game changer. They take practice and good design, but once you know their secrets, they’re easier and faster to write than slow, flaky tests. Here’s how.

...to continue reading, buy the book!

In this Section

  1. Fast, Reliable Tests
    1. Rely on Narrow Unit Tests
      1. Sidebar: Other Unit Test Definitions
    2. Test Outside Interactions with Narrow Integration Tests
    3. Simulate Nonlocal Dependencies
    4. Control Global State
    5. Write Sociable Tests
    6. Separate Infrastructure and Logic
    7. Use Broad Tests Only as a Safety Net
    8. Adding Tests to Existing Code
    9. Prerequisites
    10. Indicators
    11. Alternatives and Experiments
    12. Further Reading

Discuss the book on the AoAD2 mailing list or Discord server. Or come to the weekly book club!

For more excerpts from the book, see the Second Edition home page.

If you liked this entry, check out my best writing and presentations, and consider subscribing to updates by email or RSS.