I swear this is not a shitpost
An adaptation of PropEr for the Elixir world.
WARNING!: As of right now, this is a prototype. Feel free to open issues and send pull requests!
Add the library as a dependency for the test
environment
defp deps do
[
{:propex, "~> 0.1", only: :test}
]
end
Suppose that you want to test the following module:
# lib/my_lib.ex
defmodule MyLib do
@spec add(a :: integer(), b :: integer()) :: integer()
def add(a, b), do: a + b
end
You can automatically generate the argument list assuming that you had written
a @spec
for your function:
# test/my_lib_test.exs
defmodule MyLibTest do
use ExUnit.Case
use PropEx
test "add/2" do
forall arguments_of MyLib.add/2 do
# a, b and result are assigned automatically
result - a == b &&
result - b == a
end
end
end
You can specify the variables and types yourself if you want to
# test/my_lib_test.exs
defmodule MyLibTest do
use ExUnit.Case
use PropEx
test "add/2" do
forall [a :: integer(), b :: integer()] do
MyLib.add(a, b) == a + b
end
end
end