Property-based testing helps you create better, more solid tests with little code. By using the PropEr framework in both Erlang and Elixir, this book teaches you how to automatically generate test cases, test stateful programs, and change how you design your software for more principled and reliable approaches. You will be able to better explore the problem space, validate the assumptions you make when coming up with program behavior, and expose unexpected weaknesses in your design. PropEr will even show you how to reproduce the bugs it found. With this book, you will be writing efficient property-based tests in no time.
Most tests only demonstrate that the code behaves how the developer expected it to behave, and therefore carry the same blind spots as their authors when special conditions or edge cases show up. Learn how to see things differently with property tests written in PropEr.
Start with the basics of property tests, such as writing stateless properties, and using the default generators to generate test cases automatically. More importantly, learn how to think in properties. Improve your properties, write custom data generators, and discover what your code can or cannot do. Learn when to use property tests and when to stick with example tests with real-world sample projects. Explore various testing approaches to find the one that's best for your code. Shrink failing test cases to their simpler expression to highlight exactly what breaks in your code, and generate highly relevant data through targeted properties. Uncover the trickiest bugs you can think of with nearly no code at all with two special types of properties based on state transitions and finite state machines.
Write Erlang and Elixir properties that generate the most effective tests you'll see, whether they are unit tests or complex integration and system tests.
What You Need
- Basic knowledge of Erlang, optionally Elixir
- For Erlang tests: Erlang/OTP >= 20.0, with Rebar >= 3.4.0
- For Elixir tests: Erlang/OTP >= 20.0, Elixir >= 1.5.0
Table of Contents
Part I. The Basics
- 1. Foundations of Property-Based Testing
- 2. Writing Properties
- 3. Thinking in Properties
- 4. Custom Generators
Part II. Stateless Properties in Practice
- 5. Responsible Testing
- 6. Properties-Driven Development
- 7. Shrinking
- 8. Targeted Properties
Part III. Stateful Properties
- 9. Stateful Properties
- 10. Case Study: Bookstore
- 11. State Machine Properties
- A1. Solutions
- A2. Elixir Translations
- A3. Installing PostgreSQL
- A4. Generators Reference
- Title: Property-Based Testing with PropEr, Erlang, and Elixir
- Release date: January 2019
- Publisher(s): Pragmatic Bookshelf
- ISBN: 9781680506211