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, ... |
Get Property-Based Testing with PropEr, Erlang, and Elixir now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.