How to Approach Automated Testing

Programmers rarely have trouble writing code, but they find it extremely hard to write tests before writing code.

One reason for that is programming is really a series of small experiments carried in sequence, every single day—it’s an act of continuous discoveries. We write some code, see it fail, read up a bit, give it another shot, try out a few different paths, and through small trials and errors we get the code to work—that’s natural, that’s how we write code.

When we don’t have a clear picture of the code, how can we write tests first? It seems counterintuitive, but there are ways to work that in.

First, take small steps. If a test appears too hard to implement, the chances are we’re taking ...

Get Test-Driving JavaScript Applications 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.