1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
function assert(expression) {
/* Throws AssertException if the given expression evaluates to false.
*/
if (!expression) throw "AssertException";
}
function TestCase() {
/* TestCase objects have a setUp() and a tearDown() method,
* called before and after each test respectively.
* Tests in a TestCase have method names starting with "test".
*/
this.setUp = function() {
return;
};
this.tearDown = function() {
return;
};
this.testMethod = function() {
assert(true == false);
};
}
function run(tests) {
/* Executes each method which name starts with "test",
* for each TestCase object in the given array.
* Throws AssertException if the method fails.
*/
for (var i=0; i < tests.length; i++) {
for (var method in tests[i]) {
if (method.substring(0,4) == "test") {
tests[i].setUp();
try {
tests[i][method]();
} catch(e) {
console.error(e + " in " + method + "()");
}
tests[i].tearDown();
}
}
}
}
|