var test = args.test;
var command = args.command;
+ // args.testCaseName uses the string name of the test.
if (args.testCaseName) {
var testCases = getAllTestCases();
name = args.testCaseName;
break;
}
}
- } else if (args.testCase) {
+ } else if (args.testCase) { // The class name of the test.
name = args.testCase;
eval("tc = new " + args.testCase + "()");
}
+
+ // If the test class is defined.
if (tc != null) {
- if (args.command) {
- if (args.command == "runAllTests") {
- console.log("Running all tests for " + args.testCase);
- postResults(tc.runAllTests());
- }
- if (args.command == "runTest") {
- console.log("Running test " + args.testCase + "." + args.test);
- postResults(tc.runTest(args.test));
+ if (args.command == "runAllTests") {
+ console.log("Running all tests for " + args.testCase);
+ postResults(tc.runAllTests());
+ }
+ if (args.command == "runTest") {
+ console.log("Running test " + args.testCase + "." + args.test);
+ postResults(tc.runTest(args.test));
+ }
+ } else {
+ if (args.command == "runAllTests") {
+ console.log("Running all tests for all test cases");
+ var testCases = getAllTestCases();
+ var results = {};
+ for (var idx in testCases) {
+ var entry = testCases[idx];
+ var prototype = entry.testCase;
+ tc = new entry.testCase();
+ results[entry.name] = tc.runAllTests();
}
+ postResults(results);
}
}
}
- function postResults(results) {
- var body = document.getElementsByTagName("body")[0];
- var div = document.createElement("div");
- body.insertBefore(div, body.firstChild);
+ function postResults(results, title, div) {
+ var first = false;
+ if (div == null) {
+ var body = document.getElementsByTagName("body")[0];
+ div = document.createElement("div");
+ div.innerHTML = "Test results:";
+ if (typeof(results) != "boolean"); {
+ div.innerHTML = "Test results:<br/>";
+ }
+ body.insertBefore(div, body.firstChild);
+ first = true;
+ }
var resultToHtml = function(result) {
return result ?
}
if (typeof(results) == "boolean") {
- div.innerHTML = "Test results: " + resultToHtml(results);
+ var elem = document.createElement("div");
+ if (title) {
+ elem.innerHTML = title + ": " + resultToHtml(results);
+ } else {
+ elem.innerHTML = resultToHtml(results);
+ }
+ div.appendChild(elem);
} else { // hash
var html = "";
for (var key in results) {
if (results.hasOwnProperty(key)) {
- html = html + key + ": " + resultToHtml(results[key]) + "<br/>";
+ var elem = results[key];
+ if (typeof(elem) == "boolean" && title) {
+ postResults(results[key], title + "." + key, div);
+ } else {
+ postResults(results[key], key, div);
+ }
}
}
- div.innerHTML = "Test results:<br/>" + html;
}
- div.appendChild(document.createElement("hr"));
+ if (first) {
+ div.appendChild(document.createElement("hr"));
+ }
}
</script>
</head>
if (tc == null) {
description.innerHTML = "Test cases:";
var testCases = getAllTestCases();
+ createLink(list, "(run all tests)", document.URL + "?command=runAllTests");
for (var idx in testCases) {
var entryName = testCases[idx].name;
createLink(list, entryName, document.URL + "?testCaseName=" + entryName);