PropCheck.Properties (PropCheck v1.4.1) View Source

This module defines the property/4 and property/1 macros. It is automatically available by use PropCheck.

Link to this section Summary

Functions

Defines a not yet implemented property.

Defines a property as part of an ExUnit test.

Link to this section Functions

Link to this macro

property(message)

View Source (macro)

Defines a not yet implemented property.

This convenient macro provides a property which will always flunk. It resembles the test/1 macro from ExUnit. Similarly to ExUnit, it also tags the test with :not_implemented, allowing to filter it when running mix test.

Example

property "This property will be implemented in the future"

Link to this macro

property(name, opts \\ [], var \\ quote do _ end, list)

View Source (macro)

Defines a property as part of an ExUnit test.

The property macro takes at minimum a name and a do-block containing the code of the property to be tested. The property code is encapsulated as an ExUnit test case of category property, which is released as part of Elixir 1.3 and allows a nice mix of regular unit test and property based testing. This is the reason for the third parameter taking an environment of variables defined in a test setup function. In ExUnit, this is referred to as a test's "context".

The second parameter sets options for Proper (see PropCheck ). The default is :quiet such that execution during ExUnit runs are silent, as normal unit tests are. You can change it e.g. to :verbose or setting the maximum size of the test data generated or what ever may be helpful. For seeing the result of wrapper functions PropCheck.aggregate/2 etc., the verbose mode is required.

Counter Examples

If a property fails, the counter example is in a file. The next time this property is checked again, only the counter example is used to ensure that the property now behaves correctly. Additionally, a property with an existing counter example is embellished with the tag failing_prop. You can skip all other tests and property by running mix test --only failing_prop. In this case only the properties with counter example are run. Another option is to use the --stale option of ExUnit to reduce the amount of tests and properties while fixing the code tested by a property.

After a property was ran successfully against a previous counter example, PropCheck will run the property again to check if other counter examples can be found.

Disable Storing Counter Examples

Storing counter examples can be disabled using the :store_counter_example tag. This can be done in three different scopes: module-wide scope, describe-wide scope or for a single property.

NOTE that this facility is meant for properties which cannot run with a value generated in a previous test run. This should usually not be the case, and :store_counter_example should only be used after careful consideration.

Disable for all properties in a module:

defmodule Test do
  # ...
  @moduletag store_counter_example: false
  #...
end

Disable for all properties in a describe block:

defmodule Test do
  # ...
  describe "describe block" do
    @describetag store_counter_example: false
    # ...
  end
end

Disable for a single property:

@tag store_counter_example: false
property "a property" do
  # ...
end