Macchiato is testing framework for JavaScript, inspired by QuickCheck, a similar library for Haskell programs.
About QuickCheck
from QuickCheck module description
QuickCheck is a library for random testing of program properties.
The programmer provides a specification of the program, in the form of properties which functions should satisfy, and QuickCheck then tests that the properties hold in a large number of randomly generated cases.
Specifications are expressed in Haskell, using combinators defined in the QuickCheck library. QuickCheck provides combinators to define properties, observe the distribution of test data, and define test data generators.
see voqn.github.com/macchiato/
please see GitHub Milestones
Use macchiato.stock( labeled_properties )
macchiato.stock({ // stock test properties as object
'number x, y => x + y === y + x' : // <label>:<callback>
arbitrary( 'number', 'number' ).property( function( x, y ){
return x + y === y + x; // boolean
})
}).taste(); // run all stocked test suites
in default, macchiato.js generate 100 pattern argument per test-property.
Use macchiato.taste()
macchiato.taste(); // check all stocked test quite. and display test result
Use arbitrary.sample( opt_count )
arbitrary( 'boolean' ).sample( 5 ); // [ true, false, false, true, true ]
arbitrary( 'boolean' ).sample( 5 ); // [ false, false, true, false, true ]
// in default, return array has 10 elements
arbitrary( 'integer' ).sample(); // [ 0,1,1,0,-1,6,6,-12,-2,16 ]
Use arbitrary( type_signature ).fmap( modifier_callback )
// Non Negative Integer generator
arbitrary('integer').fmap( function( n ){
return Math.abs( n );
}).property( function( x ){
return x > -1;
});
Use arbitrary( type_signature ).recipe( generator_callback )
arbitrary( 'hoge' ).recipe(
combinrator.elements( ['hoge', 'huga', 'foo', 'bar'] )
);
Or, arbitrary( type_signature ).recipeAs( new_type_signature )
arbitrary( 'integer' ).fmap( function( n ){
var x = Math.max( Math.abs( n ), 1 );
return x % 15 == 0 ? 'FizzBuzz' : x % 5 == 0 ? 'Buzz' : x % 3 == 0 ? 'Fizz' : x;
}).recipeAs( 'fizzbuzz' );