Machiatto
Behaviour driven test framework.
Features
- BDD friendly syntax
- Context re-use between tests and files
- Better structure for same context tests
- Sync and async code testing
- Browser and node.js
Status
Project is currently under heavy development and not yet ready for production usage.
Checkout current Road Map to 0.2.0
stable version.
Usage
Install machiatto
as npm package,
> npm install machiatto --save
Create helloworld.spec.js
file,
var behaviour = ;var expect = ; var spec = ; spec ; moduleexports = spec;
Then in byeworld.spec.js
file,
var behaviour = ;var expect = ; var spec = ; spec ; moduleexports = spec;
See /test.
API
All tests are grouped by suites. To start new suite
, call machiatto
function with spec name,
var machiatto = ; var spec = ;
spec
when()
is a function that establish context for test. For async tests it supports second parameter done()
as callback function.
when()
expected to do one (and only one) action. If you need to extend context, there is .and()
function for that,
spec
The assert is expected to be done in .should()
function. .should()
is never async and takes only one parameter - context
.
spec ;
As .when()
and .and()
functions, .should()
suppose to verify only one aspect of behaviour. Ideally it should contain of one expect()
call. No async calls, no initialization of context (or actions) are supposed to be done inside .should()
.
The spec
have to be exported from module, to allow runner to execute it.
moduleexports = spec;
Context re-usage
Once .when()
or .and()
function is called it's possible to reuse it's body within same suite by name.
spec ; spec ;
X-functions
It's possible to prevent and of .when()
, .and()
or .should()
from execution, by prefix function name with x
- .xwhen()
, '.xand()' and .xshould()
.
spec // this one will be skipped.. ;
Execution flow
You can manage execution flow of specs with .skip()
and .only()
functions.
spec // only this spec will run ; spec // this spec will be excluded of execution
Motivation
Machiatto is Mocha inspired frawemork. There was several motivation points, why I think it's time to reconsider Mocha.
-
Mocha supposed to be BDD framework. Each time I try to explain BDD priciples with Mocha, it appears to be hard because of inspite of common BDD language of
"given-when-then"
, it exposes API based on"describe-before-it"
methods, that makes inpedence mismatch between BDD language and framework itself. -
In Mocha nested context are nested
describe
functions. With too many nested contexts, the code blocks move right and it's a harder to read such code and maintantain it. Besides, the code re-use between specs are impossible, some many times you put it to some utitlity objects and call from specs. -
Mocha exposes all their API as global functions, so
describe
orit
are usually warnings forjshint
.
Machiatto is an effort to fix Mocha and provide better BDD testing framework.
License
MIT
(c) 2014 alexander.beletsky@gmail.com