Here’s What Happened: Five Things We Learned About Unit Tests from David Scott Bernstein

Here’s What Happened: Five Things We Learned About Unit Tests from David Scott Bernstein

Paige Watson
Paige Watson
September 11, 2018

Learning, sharing, growth. Those three things are what brought together 60 software crafters on a Thursday evening in Seattle, Washington.

David Scott Bernstein, the author of "Beyond Legacy Code," gave a presentation at the Seattle Code Crafters meetup on effective test-driven development (TDD) techniques that support building useful tests and quality code.

TDD is an approach to programming that has developers write tests of their code before they write the actual code itself, guaranteeing full code test coverage at every step of development. This practice allows developers to focus on writing new features and refactoring code by quickly showing changes that may introduce bugs in other parts of the code base. It creates a culture of confidence in a developer’s ability and a safe way to implement innovative solutions.

In his talk, "Unit Tests as Specifications,” Bernstein outlined how writing good unit tests is a critical skill that developers need to master in order to productively implement TDD. He provided insights on how to instrument unit tests, write tests for refactored code, keep test coverage high, and specify the right kind and number of unit tests needed to specify any behavior.

Here are our top five takeaways from Bernstein’s talk:

  1. The unit tests we write with TDD can do more than just verify our code. They can also serve as clear specifications for creating testable behaviors that support refactoring.

  2. Tests must be unique, written at the right level of abstraction, and implementation-independent in order to be most valuable. When we understand how to use tests to articulate the behaviors we want to create, we can recognize the correct number and kind of tests needed to describe the behavior we want to build, putting every member of a team on the same page and building the right kind and number of tests that drive the creation of any behavior in the system. When we do this, our tests become a form of living specifications.

  3. Write a test first, with the test name and assertions focused more on the requirements than on the output of a single method or function. This will allow the developers to write the necessary code to fulfill the requirements.

  4. Using unit tests as a test of specifications is a great way to add test first development into the refactoring of legacy code bases.

  5. As we become more dependent on code through the technologies we use as a part of everyday life, developers must adhere to code quality practices. Otherwise, we ultimately create more and more problems down the line. These code quality practices, like TDD, are essential to the health and growth of our industry.

As a strong supporter, Bernstein shared some final thoughts on the Code Craft movement:

“In any field, there are levels of mastery and software development is no different. Software Craftsmanship is about upping our game to produce code that not only does the job but is written clearly so it’s straightforward to comprehend and extend in the future.”

For more of Berstein’s thoughts on unit testing and agile software, follow him on Twitter (@ToBeAgile) or read one of his recent posts on his blog. Find out about upcoming activities in Seattle and the Eastside by visiting the Seattle Code Crafters meetup page.

To learn more or get connected with the coding community, visit the 8th Light Community Page for a list of organizations, conferences, and meetups.