Let’s Get Practical

Here are some ways to put these ideas into practice.

Seven Strategies for Using Tests as Specifications

Writing unit tests to specify behaviors keeps development focused on building only what’s needed. It also helps you limit the tests you write to only those that specify the behavior you’re creating. Not only do these tests document how to use the behaviors you create, they also show the sequence in which you built a feature, which gives insight as to how the software was designed. Here are seven strategies for using tests as specifications.

Instrument your tests

Instead of using hardcoded values as parameters, assign those values to variables that are named for what they represent (for example, maxUsers instead of 20). This ...

Get Beyond Legacy Code now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.