Let's learn about a unique testing technique known as Property-Based Testing.

Even the best-designed unit tests are limited to the number of inputs we can throw at our code. In this chapter, we’re going to learn about a new testing technique called property-based testing.


Property-based testing introduces randomness into our tests by generating random inputs to feed to our code. This increases our confidence in the code and can lead to discovering pesky bugs by generating weird edge cases. Property-based testing also forces us to think differently about the accepted inputs and the properties of our code, often helping with the design and implementation.

Property-Based Testing

A while ago, an issue was opened in the Elixir language repository reporting a problem with String.replace/3. The String.replace/3 function takes a subject string, a pattern string, and a replacement string. The job of the function is to replace the pattern string with the replacement string in the subject string.

Get hands-on with 1200+ tech skills courses.