Chapter 7
Property-Based Testing

Even the best-designed unit tests are limited to the number of inputs you can throw at your code and that you can come up with. You can use some sort of enum wrapper around a test or try to come up with edge cases, but you’re still limited to the inputs that you can actually type out, often leaving out problematic inputs because, well, you never thought of them.

In this chapter, you’re going to learn about a new testing technique called property-based testing. Property-based testing introduces randomness into your tests by generating random inputs to feed to your code. This increases your confidence in the code and can lead to discovering pesky bugs by generating weird edge cases. Property-based testing also forces you to think differently about the accepted inputs and the properties of your code, often helping with the design and implementation.

The goal of this chapter is to introduce you to the basics of property-based testing and when and how to integrate it into your test suite. You’ll also learn about a particular tool called stream_data,[47] a fairly common property-based testing framework for Elixir written by one of the authors of this book (Andrea), but the concepts and ideas discussed here apply to most frameworks you’ll find in the wild.

Let’s start the chapter with an anecdote that we think captures the power and usefulness of property-based testing.

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

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