520

# Property-based Testing is a Mindset

## Andrea Leopardi

December 06, 2017

## Transcript

1. ### I S A M I N D S E T

P R O P E R T Y - B A S E D T E S T I N G

3. None

8. ### test "sorting" do assert sort([]) == [] assert sort([1, 2,

3]) == [1, 2, 3] assert sort([2, 1, 3]) == [1, 2, 3] end example-based
9. ### table-based Input Output [] [] [1, 2, 3] [1, 2,

3] [2, 1, 3] [1, 2, 3]

16. ### test "sorting" do assert sort([]) == [] assert sort([1, 2,

3]) == [1, 2, 3] assert sort([2, 1, 3]) == [1, 2, 3] end

19. ### check all list <- list_of(int()) do sorted = sort(list) assert

is_list(sorted) assert same_elements?(list, sorted) assert ordered?(sorted) end
20. ### check all list <- list_of(int()) do sorted = sort(list) assert

is_list(sorted) assert same_elements?(list, sorted) assert ordered?(sorted) end
21. ### check all list <- list_of(int()) do sorted = sort(list) assert

is_list(sorted) assert same_elements?(list, sorted) assert ordered?(sorted) end
22. ### check all list <- list_of(int()) do sorted = sort(list) assert

is_list(sorted) assert same_elements?(list, sorted) assert ordered?(sorted) end
23. ### check all list <- list_of(int()) do sorted = sort(list) assert

is_list(sorted) assert same_elements?(list, sorted) assert ordered?(sorted) end

29. ### property "encoding->decoding is circular" do check all bin <- binary()

do encoded = Huffman.encode(bin) assert is_binary(encoded) assert Huffman.decode(encoded) == bin end end Huffman encoding

33. ### property "gives same results as Erlang impl" do check all

bin <- binary() do assert Huffman.encode(bin) == :huffman.encode(bin) end end

36. ### https://www.youtube.com/watch?v=jvwfDdgg93E property "only expected codes are returned" do check all

request <- request() do response = HTTP.perform(request) assert response.status in [200, 201, 400, 404] end end

38. ### if System.get_env("CI") == "true" do config :stream_data, max_runs: 500 else

config :stream_data, max_runs: 25 end

40. ### R E A L - W O R L D

E X A M P L E

43. ### property "splitting commands at random" do check all cmd <-

command(), split_cmd <- random_splits(cmd) do assert {:ok, _, ""} = parse_many(split_cmd) end end
44. ### property "splitting commands at random" do check all cmd <-

command(), split_cmd <- random_splits(cmd) do assert {:ok, _, ""} = parse_many(split_cmd) end end
45. ### property "splitting commands at random" do check all cmd <-

command(), split_cmd <- random_splits(cmd) do assert {:ok, _, ""} = parse_many(split_cmd) end end

S T I N G

59. ### find obscure bugs reduce to minimal failing input find specification

errors keep increasing input space