Chapter 7. Unit Testing

Unit testing is the professional developers’ most efficient strategy for ensuring that they indeed complete their programming tasks, that the code they write works in accordance with their assumptions,1 and that it can be changed by them and their peers.

1. It’s tempting to write “works correctly” instead of “works in accordance with their assumptions,” but proving that a program is correct is impossible, except for simplistic snippets used in a university course on formal methods.

A hobby hack written and used by one person doesn’t need to have unit tests. One person suffers the consequences of bugs, and if any refactorings take more time than necessary or totally break the project, that’s probably fine too. If the project ...

Get Developer Testing: Building Quality into Software 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.