About jsUnity
What is it?
jsUnity is a lightweight JavaScript testing framework that is context-agnostic. It doesn’t rely on any browser capabilities and therefore can be used in any client-side or server-side JavaScript environment: Firefox, Internet Explorer, Safari, Opera, Google Chrome, Classic ASP/WSH (JScript), Rhino etc.
Why jsUnity?
There are already several unit testing frameworks for JavaScript that are browser-centric. jsUnity aims to just focus on JavaScript as a language that’s used beyond the browser context.
In a nutshell…
The most concise way of running a test suite with jsUnity:
var results = jsUnity.run(function () {
function testSomething() {
jsUnity.assertions.assertTrue(someFlag);
}
});
Alternative ways for defining test suites:
function testSuite1() {
function testSomething1() {}
}
var testSuite2 = {
suiteName: "testSuite2",
testSomething2: function () {}
}
function testSomething3() {}
var testSuite3_1 = [ testSomething3 ];
var testSuite3_2 = [ "testSomething3" ];
var testSuite4 = "function testSomething4() {}";
jsUnity.log = function (s) {
document.write("<div>" + s + "</div>");
};
jsUnity.run(testSuite1, testSuite2,
testSuite3_1, testSuite3_2, testSuite4);
Here’s the output you’d get from the above:
Running testSuite1
1 test found
[PASSED] testSomething1
Running testSuite2
1 test found
[PASSED] testSomething2
Running unnamed test suite
1 test found
[PASSED] testSomething3
Running unnamed test suite
1 test found
[PASSED] testSomething3
Running unnamed test suite
1 test found
[PASSED] testSomething4
5 tests passed
0 tests failed
16 milliseconds elapsed
Head over to the tutorial or the reference for all the details. Run jsUnity’s own unit tests in your browser, in Classic ASP or even on your Windows desktop to see it in action.