Introduction to Responsible Testing

Get introduced to the concept of responsible testing and what we will go through in this chapter.

What is responsible testing?

Understanding when and where properties work best is important for responsible testing, and that is what we are going to learn in this chapter.

Throughout the chapter, we’ll take on a practical project based on the birthday greeting “kata” by Matteo Vaccari. This exercise asks us to organize unit tests for a little application in a manner such that as few tests as possible will need to be modified or trashed when implementation details or requirements change.

The exercise will contain parts having to do with data storage, text parsing, data manipulation, and templating. We will only focus on unit tests, and we’ll leave integrations and systems with side effects for later chapters. In this chapter, we’ll go through how to choose between traditional example-based testing and property-based testing.

The specifications of the example

We’re going to write a program that will first load a set of employee records from a flat file and then send a greeting email to each employee whose birthday is today. In our example, the flat file we receive contains employee records and looks a bit like a comma-separated-values (CSV) file. We’re given this sample:

last_name, first_name, date_of_birth, email
Doe, John, 1982/10/08, john.doe@foobar.com
Ann, Mary, 1975/09/11, mary.ann@foobar.com

The email sent on an employee’s birthday should contain text like:

Subject: Happy birthday!
Happy birthday, dear John!

On its own, this is straightforward. The challenge comes from the additional constraints that we’re given:

  • The tests written should be unit tests, meaning none of the tests should talk to a database, touch the filesystem, interact with the network, or toy with the environment. Tests that do any of these are qualified as integration tests and are out of our scope.

  • We won’t use the CSV format forever. Eventually, a database or web service should be used to fetch the employee records, similarly to send the email. The tests should be written to require as few modifications as possible whenever these implementation details change.

Get hands-on with 1200+ tech skills courses.