[Elixir]property based testing with stream_data

Elixir will bundle property-based testing in the core.
http://elixir-lang.github.io/blog/2017/10/31/stream-data-property-based-testing-and-data-generation-for-elixir/

We can see the prototype for the library from https://github.com/whatyouhide/stream_data .

The following lines are the example I applied the library before.

  use ExUnitProperties

  property "get body" do
    check all body <- StreamData.binary(),
              max_runs: 50 do
      value = %{"request" => %{"method" => "GET",
            "path" => "/request/path", "port" => 8080},
            "response" => %{"body" => body, "cookies" => %{},
            "headers" => %{"Content-Type" => "text/html; charset=UTF-8",
              "Server" => "GFE/2.0"}, "status_code" => 200}}
      assert Body.get_body(value) == body
    end
  end

https://github.com/KazuCocoa/http_proxy/pull/47/commits/11bf6ff5a763c97c3ec6c7bc4a1811de53a6d0c2

We can see more details from https://hexdocs.pm/stream_data/StreamData.html and you can see how flexible the methods.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.