Anyone who has hung around me knows that I am a big fan of property based tests. I think that having the computer generate tests is a great way to find those strange corner cases that you would not have thought to check. I have found strange escaping bugs in database integrations and many other things this way.

But there are a few classes of defect that will be hard to find in a quickcheck type test. Take this function in JavaScript it will take a number and return true or false depending on the value of the number. In the first case the cutoff value is 19 and quickcheck will find that pretty quickly.

function isLarge ( v ){ if ( v > 19 ) return true ; if ( v < 19 ) return false ; }

But take this code, here the value is 196913.

function isVeryLarge ( v ){ if ( v > 196913 ) return true ; if ( v < 196913 ) return false ; }

We can write a quickcheck property using jsverify, mocha and underscore.js like this

var assert = require ( 'assert' ); var jsc = require ( "jsverify" ); var _ = require ( "underscore" ); describe ( "IsVeryLarge" , function (){ jsc . property ( "IsVeryLarge" , "integer" , function ( arr ) { return _ . isBoolean ( isVeryLarge ( arr )); }); });

The problem is that the chance that the generator will come up with the specific number 196913 is one in 2^32^ or whatever the range of integers that the tool is using. So the chance that you will find that one value is kind of like trying to find a golf ball in an area the size of a city by just checking random locations.

So should you use quickcheck? Yes you should, but you should also keep an eye on things like code coverage and branch coverage because it is possible that you have that one very strange corner case that will never be found this way.

Find QuickCheck interesting? I have books on using it in Erlang, Elm and JavaScript (In development).