Lawrence_elixir

Lawrence_elixir

13) ElixirConf EU 2019 - Introduction to stateful property based testing - Tomasz Kowal

@tomekowal - Software Developer at ClubCollect

Introduction to stateful property based testing

Talk in three words: Stateful Property-Based Testing

Abstract
Property-based testing is a technique for writing tests that use a framework for creating test inputs and user-defined properties for validating outputs. Generating data allows for finding bugs that would be impossible to catch by regular unit tests: e.g. too big to encode by hand. This talk will explain why it is worth getting into PBT by introducing successful usages of PBT for testing AUTOSAR, LevelDB and Dropbox. All these examples use stateful testing, so the second half of the talk describes steps to create a stateful test for a simple key-value store.

Objectives
Introductory materials for PBT often focus on straightforward cases which are great for teaching but fail to show the true potential of PBT. The goal of this talk is a high-level overview that is both encouraging for beginners but also maps the road to mastering Property-Based Testing.

Audience
Developers who have heard about Property-Based Testing but are not convinced yet about its usefulness.

The speaker
Tomasz has worked with functional languages for over eight years and loves learning and teaching about concepts and techniques.

All will be added to the ElixirConf EU 2019 Talks List or via the #elixirConfEU2019 tag.

Most Liked

keathley

keathley

If you’re testing with timers then you’ll want to add the timers to the model itself. After all time is part of your state at that point. You can treat timer calls as a command to generate. This allows you to deterministically control your tests and consequently run them much faster. It also allows you to induce weird failures that you wouldn’t normally see (like firing timers in incorrect orders for instance). I typically do this by shimming the timer module. My SUT uses the shim. In production it’ll use the real timer module. In my tests they’re just dummy calls.

tomekowal

tomekowal

Is that a standard cache?
I am not sure I would use PBT for such case. It makes sense where there is an explosion of different states. In case of cache, there are two: the data is there, or it isn’t.
Other argument for not testing it this way is that usually after deleting the session, you fetch it from the DB or somewhere else. It doesn’t affect how your system behaves to the outside world. It is an implementation detail that can you should leave out of model.
If there is other stuff depending on it, and you want to test it with PBT, you can pass current time to the functions as an argument. That makes it easier to test in general - not only for PBT :slight_smile:

jmitchell

jmitchell

That’s not what I had in mind, but those are good points.

Oh that makes sense–thanks.

The example requirement was intended as an explicit feature of the server API. Although clients can’t be sure data isn’t retained longer without being able to audit the running code, they can at least know the server behave as if they have a clean slate after waiting >70s. The PBT would help in case this guarantee ever needed to be audited and help maintain the guarantee as the implementation evolves.

Another potential reason for the requirement is avoiding per connection session data becoming a memory leak.

Where Next?

Popular in Talks Top

axelson
ElixirConf 2017 - Keep an Eye on the Sky with Nerves and Phoenix - @electricshaman As part of the next gener...
New
CodeSync
Hologram Building Rich UIs with Elixir Running in the Browser - Bart Blast | ElixirConf EU 2025 Comments welcome! View th...
New
axelson
ElixirConf 2017 - Its Better Unstated - @tjstankus This is a story about transitioning an obsession with obj...
New
axelson
ElixirConf 2017 - Cajoling the Bird: How we squeezed more out of Phoenix PubSub- Simon Zelazny Grindr is a m...
New
TwistingTwists
I am in middle of watching this. I have to stop every minute and think over what Chris just said. The amount of info he sends over that ...
New
ElixirConf
ElixirConf: ElixirConf 2023 - Charlie Holtz - Building AI Apps with Elixir Comments welcome! View the <span class="hashtag-icon-placehol...
New
lawik
A single packet to begin. The 1st of Goatcember. Marc Laines - A Nerves Car Also on YouTube.
New
blatyo
Looks like videos have started to go up for ElixirConf US 2018. Here’s the playlist of ones available so far. I expect it’ll get updated ...
New
Lawrence_elixir
ElixirConf EU 2019 talk videos ElixirConf EU 2020 - Early bird tickets on sale now! Website: http://www.elixirconf.eu Twitter: www.t...
New
axelson
by @jola Can you write a performant string processing scripts in Elixir? This talk attempts to answer that question while incrementally...
New

Other popular topics Top

sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement