Skip to content

VoQn/macchiato

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Macchiato.js - BDD + QDD testing framework for JavaScript -

Macchiato is testing framework for JavaScript, inspired by QuickCheck, a similar library for Haskell programs.

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.

Demo page

see voqn.github.com/macchiato/

Sorry. now Macchiato.js is under development

please see GitHub Milestones

Sample code

Register test suites

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.

Run Test Suites

Use macchiato.taste()

macchiato.taste(); // check all stocked test quite. and display test result

How to see generator works

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 adhoc new type generator

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;
});

Register User generator

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' );

About

BDD + QDD testing framework for JavaScript

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published