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.
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
Basic knowledge of Erlang, optionally Elixir For Erlang tests: Erlang/OTP >= 20.0, with Rebar >= 3.4.0 For Elixir tests: Erlang/OTP >= 20.0, Elixir >= 1.5.0
Fred Hebert is the author of 3 Erlang books and a bunch of blog posts. He co-founded and is a board member at the Erlang Ecosystem Foundation.
He works as Staff SRE at Honeycomb.io. Previously, he was a staff developer at Postmates, with a focus on learning from incidents and poking at various things. Earlier, he was Systems Architect at Genetec, a company offering security video and IoT integration systems. Even earlier, he was a principal member of technical staff on the Heroku platform, worked in real-time bidding, and provided Erlang training.
No star rating: I can't deny the book is very detailed & covers topics that do miss good materials on-line, but ... I couldn't help struggling - I really wanted to love this book, but it was boring beyond all recognition :(
The previous Fred's book is totally awesome ("Learn You Some Erlang for Great Good!"), his community talks are great, but I can't really recommend "Property-Based Testing ...". OK, but what can I say about it?
1. Please keep in mind it's about PropEr, not StreamData (the recent Elixir property testing solution) 2. Majority (70%+) examples are in both Elixir & Erlang, but some are only in Erlang (there are references to Elixir versions, but they are not directly embedded in pages) 3. The concept of generators is not trivial, some better introductory samples would make a lot of sense. But if you have a good grasp on the concept of property testing, you'll do fine.
But even with all this critique of mine, I have to admit it's great to see another Erlang/Elixir book on the market.
Fred does an excellent job of explaining the intricacies of property-based testing. He takes the reader on a journey of thoughts and not just a how-to. I love the Fred pays attention to how to generate data that matters. Other property testing resources often seem to miss that fact, and IMO, it is the most important. Property-based testing is not about random data but interesting data. Fred nails the data on the head and utilizing the current best free and OSS tool in the Elixir/Erlang ecosystem. I highly recommend getting your hands on this book.
Obviously focused on property based testing in Erlang/Elixir, but still insanely useful when doing property based testing in general, and has a lot of good stuff to say about testing discipline in general.
Before i say my opinion , you must understand i read this book (which is full of examples) without writing or testing the code samples, so i am highly biased !
Though i have read the first book of the author and it remains one of my favourite programming books, i feel this one was really cumbersome to underatand even having prior Erlang knowledge and despite the author explaining the concepts related to Property Based Testing really well.
The problem in my opinion is the language itself, Erlang. I found the examples written in it not suitable to understand what is going on there. The Erlang macros were really annoying and there is too much to understand about the framework PropEr and not about property based testing.
What i understood quite frankly from the begining is that you can't really do property based testing without an already mature existing framework on it....and this basically becomes learning a new framework....
I wad interested more in the theoretical concepts and how they could be used in general. I would have enjoyed less code and the content to be language agnostic.
This entire review has been hidden because of spoilers.
Ugh.. I think the book is a great one if you know erlang and planning to use PropEr. I have very basic familiarity with erlang syntax, have no plans for proper and picked up the book to learn something new about property-based testing. So the book was 30% hit, 70% miss for me. The theoretical part of the book felt a bit too short, the practical part felt too detailed (again because i don't plan to use proper). Overall it's not a bad intro to property-based testing, all important aspects are there and the book even tries to show the connection between formal specifications and prop-based testing, but if you have no experience with the technique i don't think this is the best way to learn about it.