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

Putting It All Together

To get started with writing our own properties, it may be useful to compare them with the type of tests we’d already have in place in an existing project. We’ll start with a simple function, one that finds the largest element in a list. Coming up with properties isn’t all easy, so beginning with regular tests can sometimes be a good idea since it can at least help us flesh out what we think the code should be doing.

Standard unit tests would probably look a bit like this, using the EUnit syntax:

 biggest_test​() ->
  ?​assert​(5 =:= ​biggest​([1, 2, 3, 4, 5])),
  ?​assert​(8 =:= ​biggest​([3, 8, 7, -1])),
  ?​assert​(-5 =:= ​biggest​([-10, -5, -901])),
  ?​assert​(0 =:= ​biggest​([0])).

With regular unit tests, we put ...

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