Design with Positive, Negative, and Exception Tests

Writing tests before writing code is a skill. It may appear hard at first, but it gets better with practice. The result of that effort is a more modular, cohesive, and loosely coupled design.

By writing tests first, we put ourselves in the shoes of the person who will be using our code before we write it. Thus, from the very first step, we can approach the design of code from the point of view of someone using the code. In this approach each function we design will be shaped by a series of tests. The first few tests will help to shape the interface of the function—that is, its skin. The tests that follow will then help shape the implementation or the guts of the function.

Let’s discuss ...

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.