Skip to Main Content
Property-Based Testing with PropEr, Erlang, and Elixir
book

Property-Based Testing with PropEr, Erlang, and Elixir

by Fred Hebert
January 2019
Intermediate to advanced content levelIntermediate to advanced
376 pages
8h 49m
English
Pragmatic Bookshelf
Content preview from Property-Based Testing with PropEr, Erlang, and Elixir

Writing Properties

As with stateful properties, we can make use of the rebar3 plugin’s templates to get a property suite within any standard Erlang project. Call the following within an existing project:

 $ ​​rebar3​​ ​​new​​ ​​proper_fsm​​ ​​name=fsm
 ===> Writing test/prop_fsm.erl

The generated file contains the prop_fsm module, a test suite that is divided in two sections: one section for the state machine property we’ll want to execute, and one for the model, which is a mix of callbacks and generators. Let’s start by looking at the property:

 Erlang
 -module(prop_fsm).
 -include_lib(​"proper/include/proper.hrl"​).
 
 -export([initial_state/0, initial_state_data/0,
  on/1, off/1, service/3, ​% State generators
  weight/3, precondition/4, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Erlang and OTP in Action

Erlang and OTP in Action

Eric Merritt, Richard Carlsson, Martin Logan
Testing Elixir

Testing Elixir

Andrea Leopardi, Jeffrey Matthias

Publisher Resources

ISBN: 9781680506556Errata Page