Skip to content

Instantly share code, notes, and snippets.

@jmingtan
Created May 13, 2010 17:30
Show Gist options
  • Save jmingtan/400107 to your computer and use it in GitHub Desktop.
Save jmingtan/400107 to your computer and use it in GitHub Desktop.
// Minimal unit testing for Rhino
// loosely based off minunit - http://www.jera.com/techinfo/jtns/jtn002.html
// same license as minunit - do whatever you want with no warranty
var jstest = function () {
var pub = {};
var currentSuite = "DefaultSuite";
pub.testsRun = 0;
pub.assert = function (message, test) {
if (false == test)
throw message;
}
pub.run = function (test) {
try {
test();
} catch (err) {
throw "Failed at " + currentSuite + " with: " + err;
}
pub.testsRun++;
}
pub.suite = function (suiteName) {
currentSuite = suiteName;
}
return pub;
}();
load("jstest.js");
function testCase() {
var foo = 7;
var bar = 5;
function testFoo() {
jstest.assert("error, foo != 7", foo == 7);
}
function testBar() {
jstest.assert("error, bar != 5", bar == 5);
}
jstest.suite("JSTestSuite");
jstest.run(testFoo);
jstest.run(testBar);
}
testCase();
print("All tests passed!");
print("Tests run: " + jstest.testsRun);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment