PropSchema
An extension of both Ecto.Schema
and ExUnitProperties
for auto-generation of changeset property tests.
Consists of two main modules: PropSchema
and PropSchema.Executor
Installation
def deps do
[
{:prop_schema, "~> 0.1.0"}
]
end
Usage
Look at the documentation for full usage
https://hexdocs.com/prop_schema
Basic Example
In example_module.ex:
defmodule ExampleModule do
use PropSchema
alias Ecto.Changeset
prop_schema "example" do
prop_field(:example_string, :string, string_type: :alphanumeric, required: true)
prop_field(:example_int, :integer, positive: true, required: false)
field(:example_float, :float)
end
def changeset(schema, data) do
schema
|> Changeset.cast(data, [:example_string, :example_int, :example_float])
|> Changeset.validate_required([:example_string])
end
end
In example_module_test.ex:
defmodule ExampleModuleTest do
use PropSchema.Executor, to_test: PropSchema.ExampleModule
end
Then run mix test
. In this example it will make 3 prop tests.
Or for a more realistic example see example module, properties, and generated tests.