eqc_ex v1.3.0 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 runs n test cases, default is 100. This tag has priority over min_time and max_time tags.
  • min_time: t - QuickCheck runs for t milliseconds unless numtests is reached.
  • max_time: t - QuickCheck runs for at most t milliseconds unless numtests is reached.
  • timeout: t - Inherited from ExUnit and fails if property takes more than t milliseconds.
  • erlang_counterexample: false - Specify whether QuickCheck should output the Erlang term that it gets as a counterexample when a property fails. Default true.

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

Summary

Macros

Defines a property with a string similar to how tests are defined in ExUnit.Case

Macros

property(message, var \\ quote() do _ end, contents)

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