FIRS[T]: [T]imely

You can write unit tests at virtually any time. You could dredge up code in any old portion of your system and start tacking on unit tests to it. But you’re better off focusing on writing unit tests in a timely fashion.

Unit testing is a good habit. With most good habits that you’ve not yet completely ingrained, such as brushing your teeth, it’s easy to procrastinate and make excuses why you can skip the practice “just this once.” Your dentist might love your funding his or her practice, but you’re going to hate the time it takes to scrape away the tartar that’s built up.

Likewise, the more you defer probing at your code with unit tests, the more plaque buildup (cruft) and cavities (defects) you’ll need to deal with. Also, ...

Get Pragmatic Unit Testing in Java 8 with JUnit now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.