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

Thinking in Properties

Question 1

Your answer could be any three of these strategies:

  • Modeling—comparing the implementation with a simpler but obviously correct one
  • Generalizing traditional tests by automating steps we would do by hand
  • Finding program invariants to validate
  • Using symmetric properties

Question.

Question 2

Two example solutions:

 Erlang code/ThinkingInProperties/erlang/pbt/test/prop_solutions.erl
 %% @doc this function tests that any lists of `{Key,Val}' pairs
 %% end up being able to be sorted by the key by using `lists:keysort/2'.
 prop_keysort1​() ->
  ?FORALL(List, ​list​({​term​(),​term​()}),
 begin
 %% is_key_ordered checks that all tuples' keys are ordered.
 is_key_ordered​(​lists​:​keysort​(1, List))
 end​).
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