basil

Hierarchical Unit Test Runner for Javascript

Contents


Syntax
Running
Filters
Debugging
Plugins
Questions?

Syntax

Entry Points: describe, when, then, it

Example:

describe("Name", function() {
  // Test logic here
});

Nesting

Nest as much as you want

describe("Outer test", function() {
 when("there's an inner test", function() {
  then("it all works!", function() {

  });
 });
 then("again if you want", function() {

 });
});

Running

Open the test page to see the results

file:///C:/code/steve/basil/tests/samples/index.html

Results

Results shown hierarchically

Red = Fail
Green = Pass

Use the "Hide Passed" checkbox if you only care about reds

Expand/Collapse at will - it will remember your selection between page loads 
(via localStorage if there's browser support)

How it runs

Test setup is rerun from the root for every  leaf node

This ensures a clean slate in your text fixture

Example

describe("Rerunning", function() {
  var foo = "bar";
  when("changing foo", function() {
    foo = "baz";
    then("it is baz", function() {
      foo.should.equal("baz");
    });
  });
  then("it is bar", function() {
    foo.should.equal("bar");
  });
});

So what actually executed?

First Test:
var foo = "bar";
foo = "baz"
foo.should.equal("baz")

Second Test:
var foo = "bar"
foo.should.equal("bar")

But wait, isn't that slow?

We have around 1500 leaf nodes running in about 10 seconds

So yes, a little slow.  If only there was...

Filters

Limits the test execution to the supplied filters

Use the link to limit the context to a specific node and all children immediately

BAM, you have speed

Debugging

"inspect" link will give you a debugger breakpoint to the failing node of the test tree

Use this to inspect the state of the variables in your tests

Note: This does not work so well for root nodes - it will land you in Sinon's test setup code

Tips

Use the inspect link when there's a problem, might be obvious

Click the filter icon on the failing node

Use the dev tools to put breakpoints in

Keep your tests small and do them incrementally to reduce need for debugging at all

Plugins

SinonJS
Used for mocking, stubbing, and recording calls

Chai.JS
Fluent assertion library. 
Provides expect() and .should APIs

Questions





?

basil

By xwipeoutx

basil

  • 765