The Typical Approaches

Most typical test cases use one of a handful of approaches.

  • Explicit: an application can simply explicitly generate test data, leading to code that looks like this:

 ~~~
 Person.create first_name: "Paul", last_name: "Revere"
 ~~~

The downside is that such code will get awkward once you’re creating enough entities with enough attributes. In short order, the data overwhelms the test.

  • Through Fixtures: an application can create test data in tabular form, and then load all of that data into the application.

 ~~~
 # person.csv
 first_name, last_name
 Paul, Revere
 ~~~

This strategy works all right, but leads to code that is hard to maintain as applications grow, because foreign keys are difficult to manage.

  • Through templates: ...

Get Functional Programming: A PragPub Anthology 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.