Property-based tests

There are two main categories of property-based tests:

  • Table-driven

  • Generator-driven

We’ve already spent a lot of time on generator-driven tests, in which the input is automatically generated (and possibly filtered) to ensure maximum edge cases are covered. Table-driven tests are a kind of middle ground between generator-driven and example-based tests. As we’ll see in this lesson, they still let us formulate properties over our code, but they also let us choose the actual input using a testing table.

Testing tables are just tables with as many columns as inputs for the unit under test. For example, if we’re testing a stand-alone pure function, we’d have as many columns as the number of parameters of the function itself and as many rows as the number of scenarios we want to test.

Get hands-on with 1200+ tech skills courses.