Answers
Here are the answers to this chapter’s questions:
- Property-based testing has several key advantages over unit testing:
- Writing a single property requires a little bit more thought than writing a single unit test, but from it,
QuickCheck
can generate an arbitrary number of unit tests. Hence, property-based testing is more productive. - Properties are often a form of documentation of the code under test. Their parametric nature means that they convey insight into many situations, whereas a unit test covers a single situation and thus offers little insight.
- The random generation of test inputs reveals problems in unexpected corners where human testers would not have looked.
There are also some disadvantages or costs associated with property-based testing:
- Writing properties requires thinking at a more abstract level and having more insight into the code. It is debatable whether this is an advantage.
- There is a setup cost when defining the
QuickCheck
framework with new data...
- Writing a single property requires a little bit more thought than writing a single unit test, but from it,