A MooTools based unit testing framework.
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
data
externals
.gitmodules
SSException.js
SSUnitTest.js
example.js
index.html
license.txt
readme.textile

readme.textile

SSUnit

Overview

SSUnit is a unit testing framework built on top of MooTools. It also testing of asynchronous code as well as testing whether the proper exceptions are thrown. It allows you to express unit tests as standard MooTools classes. It comes with two kinds of formatters, one that outputs directly to the console and another than can output to a container in the DOM.

Single tests look like the following:

var TestA = new Class({
  Extends: SSUnitTest.TestCase,
  name: "TestA",

  setup: function() {},
  tearDown: function() {},

  add: $fixture(
    "Add two numbers",
    function() { SSUnit.assertEqual(1 + 2, 3); }
  )
});

You can build a suite of tests like so:

var TestSuite = new Class({
  Extends: SSUnitTest.TestSuite,
  name: "TestSuite",

  initialize: function() {
    this.parent();
    this.addTest(TestB);
  }
});

When you’re ready to run your test you can do the following:

SSUnitTest.main();

SSUnitTest is a singleton that automatically collects tests as you instantiate them or as TestSuite instantiates them.

Asynchronous code can be tested like so:

var TestC = new Class({
  Extends: SSUnitTest.TestCase,
  name: "TestC",

  setup: function() {},
  tearDown: function() {},

  add1: $fixture(
    "Check adding two remote resources",
    function() 
    { 
      var hook = SSUnit.startAsync();
      var p1 = get("a");
      var p2 = get("b");
      (function(a, b) {
        SSUnit.assertEqual(a + b, "ac", hook);
        SSUnit.endAsync(hook);
      }.asPromise())(p1, p2);
    }
  )
})

You can start a asynchronous test with a call to SSUnit.startAsync(). This will generate a hook which can be used to declare that the test has successfully completed. You might notice that no asynchronous calls appear to be made here. This is because SSUnit is built on top of Promises, a MooTools library for simplfying request heavy code as well as enabling a simple form of delayed evaluation. Please look at here for a lengthier exposition.

Instructions

SSUnit depends on two other ShiftSpace libraries, FuncTools and Promises. They are submodules of this repository, in order to bring them in run the following after you have cloned this repo from the repo’s directory:

> cd into/git/repo
> git submodule init
> git submodule add