6.1. Commented-out tests

I don’t know who originally came up with the idea that programmers should be able to sprinkle nonexecutable comments into their source code. (If you know, please tell.) I’m glad that we have that ability, as comments can be of great help in trying to understand code.

But often, comments backfire by confusing or even misleading us. Related to tests, a particularly interesting failure mode with comments is a test method that’s been commented-out, as it doesn’t communicate anything and just confuses people. When we do that, we’re not commenting anything—we’re using comments as a poor man’s version control.

Let’s take a look.

6.1.1. Example

Not long ago I was digging out code I’d written for a project from half a decade ago. ...

Get Effective Unit Testing 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.