eqc_ex v1.4.2 EQC.ExUnit
Properties can be executed using the ExUnit framework using ‘mix test’.
A test module using properties writes ‘property’ instead or ‘test’ and uses
EQC.ExUnit
module for the macro definitions.
Example
defmodule SimpleTests do
use ExUnit.Case
use EQC.ExUnit
property "naturals are >= 0" do
forall n <- nat do
ensure n >= 0
end
end
end
Tags
Properties can be tagged similar to ExUnit test cases.
numtests:
n
- QuickCheck runsn
test cases, default is100
. This tag has priority overmin_time
andmax_time
tags.min_time:
t
- QuickCheck runs fort
milliseconds unlessnumtests
is reached.max_time:
t
- QuickCheck runs for at mostt
milliseconds unlessnumtests
is reached.timeout:
t
- Inherited from ExUnit and fails if property takes more thant
milliseconds.erlang_counterexample:
false
- Specify whether QuickCheck should output the Erlang term that it gets as a counterexample when a property fails. Defaulttrue
.:morebugs
- Runs more_bugs:showstates
- For QuickCheck state machines, show intermediate states for failing tests
Example
In the example below, QuickCheck runs the first propery for max 1 second and the second property for at least 1 second. This results in 100 tests (the default) or less for the first property and e.g. 22000 tests for the second property.
defmodule SimpleTests do
use ExUnit.Case
use EQC.ExUnit
@tag max_time: 1000
property "naturals are >= 0" do
forall n <- nat do
ensure n >= 0
end
end
@tag min_time: 1000
property "implies fine" do
forall {n,m} <- {int, nat} do
implies m > n, do:
ensure m > n
end
end
end
Checks
You may want to test a previously failing case. You can do this by annotating the property
with @check
followed by a list of labelled counter examples.
defmodule SimpleTests do
use ExUnit.Case
use EQC.ExUnit
@check minimum_error: [-1], other_error: [-3]
property "integers are >= 0" do
forall n <- int do
ensure n >= 0
end
end
end
Summary
Macros
Defines a property with a string similar to how tests are defined in
ExUnit.Case
Macros
Defines a property with a string similar to how tests are defined in
ExUnit.Case
.
Examples
property "naturals are >= 0" do
forall n <- nat do
ensure n >= 0
end
end