var testCaseList = [];
function TestCase(name) {
- this.name = name;
- this.toString = function() {
+ var testCase = function() { return this; };
+ testCase.name = name;
+ testCase.toString = function() {
return "Fake test case " + name;
};
- var testCase = function() { return this; };
testCase.prototype.setUp = function() { };
testCase.prototype.tearDown = function() { };
/**
testCase.prototype.runAllTests = function() {
// what's better than for ... in for non-array objects?
var tests = {};
+ var names = this.getTestNames();
+ for (var idx in names) {
+ var name = names[idx];
+ console.log("Running " + name);
+ var result = this.runTest(name);
+ tests[name] = result;
+ }
+ console.log(prettyPrintEntity_(tests));
+ };
+
+ testCase.prototype.getTestNames = function() {
+ // what's better than for ... in for non-array objects?
+ var tests = [];
for (var name in this) {
if (name.indexOf('test') == 0 && typeof(this[name]) == 'function') {
- console.log("Running " + name);
- var result = this.runTest(name);
- tests[name] = result;
+ tests.push(name);
}
}
- console.log(prettyPrintEntity_(tests));
- };
+ return tests;
+ }
- testCaseList.push(testCase);
+ testCaseList.push({name : name, testCase : testCase});
return testCase;
};
var num_tests = 0;
for (var i = 0; i < testCaseList.length; i++) {
- var tc_class = testCaseList[i];
+ var tc_class = testCaseList[i].testCase;
for (var name in tc_class.prototype) {
if (name.indexOf('test') == 0 && typeof(tc_class.prototype[name]) == 'function') {
if (globalTestDb.hasOwnProperty(name)) {
console.log('Loaded ' + num_tests + ' tests in ' +
testCaseList.length + ' test cases');
}
+
+function getAllTestCases() {
+ return testCaseList;
+}
var test = args.test;
var command = args.command;
- if (args.testCase) {
+ if (args.testCaseName) {
+ var testCases = getAllTestCases();
+ for (var idx in testCases) {
+ var entry = testCases[idx];
+ if (entry.name == args.testCaseName) {
+ var prototype = entry.testCase;
+ tc = new entry.testCase();
+ break;
+ }
+ }
+ } else if (args.testCase) {
eval("tc = new " + args.testCase + "()");
+ }
+ if (tc != null) {
if (args.command) {
if (args.command == "runAllTests") {
console.log("Running all tests for " + args.testCase);
<li>command - either runTest or runAllTests.
</ul>
Example: <code>local.html?testCase=ScrollingDivTestCase&test=testNestedDiv_Scrolled&command=runTest</code>
+ <p/>
+ <div id="selector"></div>
</body>
<script>
processVariables();
addGlobalTestSymbols();
+
+function createAttached(name, parent) {
+ var elem = document.createElement(name);
+ parent.appendChild(elem);
+ return elem;
+}
+
+var selector = document.getElementById("selector");
+if (selector != null) { // running a test
+ var description = createAttached("div", selector);
+ var list = createAttached("ul", selector);
+ var parent = list.parentElement;
+ if (tc == null) {
+ description.innerHTML = "Test cases:";
+ var testCases = getAllTestCases();
+ for (var idx in testCases) {
+ var entry = testCases[idx];
+ var li = createAttached("li", list);
+ var a = createAttached("a", li);
+ a.innerText = entry.name;
+ a.href = document.URL + "?testCaseName=" + entry.name;
+ }
+ } else {
+ description.innerHTML = "Tests for " + name;
+ var names = tc.getTestNames();
+ for (var idx in names) {
+ var name = names[idx];
+ var li = createAttached("li", list);
+ var a = createAttached("a", li);
+ a.innerText = name;
+ a.href = document.URL + "&test=" + name + "&command=runTest";
+ }
+ }
+}
</script>
</html>