small medium large xlarge

Property-Based Testing with PropEr, Erlang, and Elixir: Find Bugs Before Your Users Do


Cover image for Property-Based Testing with PropEr, Erlang, and Elixir

Property-Based Testing with PropEr, Erlang, and Elixir

Find Bugs Before Your Users Do


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.

Choose Your Format(s)

  • $24.95 In Stock
    • Beta: What do I get?

  • Ebooks are DRM free.

  • Ebook delivery options.

  • The Paper Book will ship on 2019-01-10 (roughly).

About this Title

Pages: 250 (est)
Published: 2019-01-10
Release: B4.0 (2018-11-01)
ISBN: 978-1-68050-621-1

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

You will need basic knowledge of Erlang, or optionally Elixir (all Erlang code is translated to Elixir). All Erlang examples have been tested and will run with Erlang/OTP 20 and Rebar3 3.6.1. All Elixir examples have been tested with Elixir 1.5.0 or newer. Any operating system with a network connection will be fine to follow along.

Contents & Extracts

This book is currently in beta, so the contents and extracts will change as the book is developed.

  • Introduction
  • The Basics
    • Foundations of Property-Based Testing excerpt
      • Promises of Property-Based Testing
      • Properties First
      • Property-based Testing In Your Project
      • Running A Property
      • Wrapping Up
    • Writing Properties
      • Structure of Properties
      • Default Generators
      • Putting it All Together
      • Wrapping Up
    • Thinking In Properties excerpt
      • Modeling
      • Generalizing Example Tests
      • Invariants
      • Symmetric Properties
      • Putting it All Together
      • Wrapping Up
    • Custom Generators
      • The Limitations of Default Generators
      • Gathering Statistics
      • Basic Custom Generators
      • Fancy Custom Generators
      • Wrapping Up
  • Stateless Properties in Practice
    • Responsible Testing
      • The Specification
      • Thinking About Program Structure
      • CSV Parsing
      • Filtering Records
      • Employee Module
      • Templating
      • Plumbing it all Together
      • Wrapping Up
    • Properties-Driven Development
      • The Specification
      • Writing the First Test
      • Testing Specials
      • Implementing Specials
      • Negative Testing
      • Wrapping Up
    • Shrinking
      • Re-centering With ?SHRINK
      • Dividing With ?LETSHRINK
      • Wrapping Up
    • Targeted Properties
      • Understanding Targeted Properties
      • Targeted Properties in Practice
      • Thinking Outside the Box
      • Wrapping Up
  • Stateful Properties
    • Stateful Properties
      • Laying Out Stateful Properties
      • How Stateful Properties Run
      • Writing Properties
      • Testing a Basic Concurrent Cache
      • Testing Parallel Executions
      • Wrapping Up
    • Case Study: Bookstore
      • Installing PostgreSQL
      • Introducing the Application
      • Writing Generators
      • Broad Stateful Testing
      • Precise Stateful Modeling
      • Refining the Tests
      • Debugging Stateful Properties
      • Parallel Tests
      • Wrapping Up
    • State Machine Properties
      • Laying Out State Machine Properties
      • How State Machine Properties Run
      • Writing Properties
      • Testing a Circuit Breaker
      • Modeling the Circuit Breaker
      • Adjusting the Model
      • Wrapping Up


Fred Hebert is the author of Learn You Some Erlang for Great Good and Erlang in Anger. He’s a systems architect at Genetec, an IP video surveillance, access control management, and license plate recognition company. He previously worked at Heroku as a tech lead, in charge of the development and maintenance of the routing systems and parts of the logging system. He has also worked in real-time bidding systems, as a professional trainer and course maintainer for Erlang Solutions Ltd., and is one of the maintainers of the principal Erlang build tool (rebar3).