Summary

Property-based testing is a supplementary technique to the traditional unit testing and behavior-driven development. It allows one to describe program properties in the form of an abstract specification, and the test data in the form of rules to apply for its generation.

Properly generated data includes edge cases, which are often ignored during example-based testing, and allows for higher code coverage.

The ScalaCheck is a framework for property-based testing with Scala. It has three main components—properties, generators, and shrinkers.

Universally quantified properties must hold for any test data in any state of the program. Conditional properties are defined for some subset of the data or specific states of the system.

ScalaCheck provides a lots of generators for standard types out of the box. The best way to create generators for custom types is by combining existing generators using suitable methods defined on them.

The role of an optional shrink is to reduce a test data set for a failing property, helping to identify a minimal failing test case.

There are a few extension libraries available which allow one to generate arbitrary case classes and ADTs (scalacheck-shapeless), cats type class instances (cats-check), and other common cases (scalacheck-toolbox).

Now, we are properly equipped to start our journey into the land of functional programming concepts, which we will cover in the next part of the book. We will start by examining some types present in the standard library, which are known as effects, such as Option, Try, Either, and Future.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.129.70.185