Skip to content

Exercises and resources to learn property based testing. Comments and partecipation are really welcome. :-)

Notifications You must be signed in to change notification settings

MirkoBonadei/journey-towards-property-based-testing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

70 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Journey towards property based testing

Some experiments on property based testing in Erlang, using Trifork QuickCheck, I will refer to it as Triq henceforth.

The point is to explore property based testing coming from some years of example based testing and learn to write properties instead of examples in order to understand the impacts it has on the "mainstream TDD". For "mainstream TDD" I mean TDD with example based testing, to me the two things (TDD and example based testing) are not related but the majority of the literature and the practice in the real world seems to bind TDD to example based testing. So let's see what comes out from this experiment. :-)

Project structure

The structure of the project is quite straightforward.

  • src: modules which contain the functions we want to test with Triq
  • test: test modules (the naming standard is <MODULE_NAME>_tests.erl) where we define the properties of our functions

Build and Check properties

The project is built with rebar, compile code and test properties is really easy:

mirko@death-star:~/code/journey-towards-property-based-testing$ ./rebar compile qc
==> triq (compile)
==> eunit_formatters (compile)
==> journey-towards-property-based-testing (compile)
==> journey-towards-property-based-testing (qc)
NOTICE: Using experimental 'qc' command
Testing my_lists_tests:prop_sum_monotonicity/0
....................................................................................................
Ran 100 tests
Testing my_lists_tests:prop_sum_identity/0
....................................................................................................
Ran 100 tests
Testing my_lists_tests:prop_sum_base_case/0
....................................................................................................
Ran 100 tests

An example of property:

This is related to the function my_lists:sum/1, which takes a list() as input and returns the sum of the elements of the list. The property should be read as:

foreach list L of natural numbers, the sum of the elements of the list L is equal to the sum of the elements of the element 0 concatenated to the list L.

prop_sum_identity() ->
  ?FORALL({L}, {list(pos_integer())},
          begin
            L1 = [0|L],
            my_lists:sum(L) =:= my_lists:sum(L1)
          end).

Resources

There is not so much material on the web, so that I try to list below some useful resources.

Readings
Videos
Code

About

Exercises and resources to learn property based testing. Comments and partecipation are really welcome. :-)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages