Created
May 13, 2010 17:30
-
-
Save jmingtan/400107 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
}(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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