PropCheck - Property Testing v1.1.3 PropCheck.TargetedPBT View Source

This module defines the top-level behaviour for targeted property-based testing (TPBT). Using TPBT the input generation is no longer random, but guided by a search strategy to increase the probability of finding failing input. For this to work the user has to specify a search strategy and also needs to extract utility-values from the system under test that the search strategy then tries to maximize.

To use TPBT the test specification macros forall_targeted, exists, and not_exists are used. The typical structure for a targeted property looks as follows:

property prop_target do          # Try to check that
  exists input <- params do      # some input exists that fullfills the property.
      uv = sut.run(input)        # Do so by running SUT with input
      maximize(uv)               # and maximize its utility value
      uv < threshold             # up to some threshold, the property condition.
  end
end

Options

For targeted properties exists a new option:

  • {:search_steps, non_negative_number}
    takes an integer defining how many search steps the searching algorithm takes. Its default value is 1_000. The effect of search_steps is similar to num_tests for ordinary properties. num_tests has no effect on the search strategy. This helps when you combine a regular property with search strategy, e.g. generating a configuration parameter and search for specific properties to hold depending on that parameter.

Most of the documentation is taken directly from PropEr.

Link to this section Summary

Functions

The exists macro uses the targeted PBT component of PropEr to try to find one instance of xs that makes the prop return true. If such a xs is found, the property passes. Note that there is no counterexample if no such xs could be found

The forall_targeted macros uses the targeted PBT component of PropEr to try that all instances of xs fullfill porperty prop. In contrast to exists, often the property here is negated

This macro tells the search strategy to maximize the value fitness

This macro tells the search strategy to minize the value fitness and is equivalent to maximaize(-fitness)

The not_exists macro uses the targeted PBT component of PropEr to try to find one instance of xs that makes the prop return false. If such a xs is found the property passes. Note that there is no counterexample if no such xs could be found

This overwrites the structural matching of PropEr for the generator with the user provided matcher function. The matcher should be of type proper_gen_next:matcher()

This uses the neighborhood function nf instead of PropEr's constructed neighborhood function for this generator. The neighborhood function fun should be of type fun(any(), {Depth :: number(), Temperature::float()} -> any()

Link to this section Functions

Link to this macro

exists(arg, list) View Source (macro)

The exists macro uses the targeted PBT component of PropEr to try to find one instance of xs that makes the prop return true. If such a xs is found, the property passes. Note that there is no counterexample if no such xs could be found.

Link to this macro

forall_targeted(arg, list) View Source (macro)

The forall_targeted macros uses the targeted PBT component of PropEr to try that all instances of xs fullfill porperty prop. In contrast to exists, often the property here is negated.

Link to this macro

maximize(fitness) View Source (macro)

This macro tells the search strategy to maximize the value fitness.

Link to this macro

minimize(fitness) View Source (macro)

This macro tells the search strategy to minize the value fitness and is equivalent to maximaize(-fitness).

Link to this macro

not_exists(arg, list) View Source (macro)

The not_exists macro uses the targeted PBT component of PropEr to try to find one instance of xs that makes the prop return false. If such a xs is found the property passes. Note that there is no counterexample if no such xs could be found.

Link to this macro

user_matcher(generator, matcher) View Source (macro)

This overwrites the structural matching of PropEr for the generator with the user provided matcher function. The matcher should be of type proper_gen_next:matcher()

Link to this macro

user_nf(generator, nf) View Source (macro)

This uses the neighborhood function nf instead of PropEr's constructed neighborhood function for this generator. The neighborhood function fun should be of type fun(any(), {Depth :: number(), Temperature::float()} -> any()