Introduction

test.it - TDD framework for javascript unit testing. TDD is not the only application for test.it. You can also use it in agile or scrum metodologies though.

Output into the Web Console and CLI from node.js are availible.

This guide is running on v1.2.2

Open Web Console to see the example.

Setup

There are differences in setup, dependent on used environment.

Testing javascript in a browser

test.it includes like other javascript files on the page. Just add <script> tag with path to test.it.js.

But it is only the core. To see results output, include firebug output module, and use firebugConsole as default printer via test.printer().

Console output is very convenient in browsers with total console API support. They are:

  • Firefox with Firebug plugin,
  • Google Chrome and other Chromium-based,
  • Safari as well.

If you are unfortunate enough to use other browser - waits for DOM output module release please.

<script src='path/to/test.it.js'></script>
<script src='path/to/test.it-firebug.js'></script>

test.printer(firebugConsole);

Testing Javascript in node.js

First of all you need to install test.it

After that - include in into your tests file with require.

That enough for CI. But if you want pretty output for results - install and include test.it-nodejs output module. And set it as default output module with test.printer.

npm install 'test.it'
npm install 'test.it-nodejs'

test = require('test.it');
nodeConsole = require('test.it-nodejs');
test.printer(nodeConsole);

 Or shorter

(test = require('test.it')).printer(require('test.it-nodejs'));

Example


test.printer(firebugConsole);

test.it( "hello world" ); // pass
test.it( 0 ); // fail

test.group('first group',function(){ // group some tests
    test.it(1)
        .comment('this'); // add comment to the test

    console.log('using tests arguments',
        test.addTime() // add time in ms spent on this test
            .it(1,2)
            .comment('tests')
            .arguments() // return test's arguments
    );
    
    test.them([1,2,true]) 
        .comment('has')
        .addTrace() // add stack trace
        .callback(function(){console.log('test passed')} // add callbacks
                 ,function(){console.log('test faild')}
                 ,function(){console.log('test ended with error')});
    
    console.log('using tests result',
        test.it(true)
            .comment('comments')
            .result() // return result [bool] of the test
    );
});

test.group('second group',function(){ // group nesting
    test.group('nested group',function(){
        test.group('deep nested group',function(){
            test.x // esclude this test from result
                .it('this test','this test')
                .comment('will be excluded and outputed by itself')
                .print(); // output similar test
        });
    });
}).comment('has it\'s own comment');

test.group('second group') // group chaining
    .group('nested group').comment('comment to nested group')
    .group('deep nested group',function(){
        test.it('and this','and this')
            .comment('will be added to deep nested group from outside');
    });
test.group('second group')
    .group('nested group')
    .group('deep nested group')
        .comment('will be printed by itself')
        .print(); // output similar group

test.print(); // output results.
console.log(test.result()) // or use it in CI