问题
I'm just starting to use QUnit and having issues.
I'm currently using TypeScript, which is a JavaScript compiler. I have my Tests in classes which parallel the structure of my main classes.
In each of those classes, I have a function called runTests().
To execute these tests, I loop through and get all the classes which end in "Test", and then call their runTests() function.
An example of the runTests() function is:
runTests = function() {
QUnit.test("5 = 5", function() {
QUnit.ok(5 == 5, "okay");
});
}
I know all of the runTests() work (as in they are called, confirmed because of console output), but at most it only ever shows me one test. It seems to always be the last test called (even with multiple tests in the same runTests()).
Is there some weird thing where QUnit resets itself which is why I'm only seeing one, or am I missing something even more fundamental?
Thanks.
The HTML I use is here, in case it matters:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>QUnit Example</title>
<link rel="stylesheet" href="qunit-git.css">
</head>
<body>
<div id="qunit"></div>
<script src="qunit-1.10.0.js"></script>
<script src="mycode.js"></script>
<script type="text/javascript">
function runTest() {
var testClasses = getClassesRecurse(Test, []);
function getClassesRecurse(target, testClasses) {
if (typeof target == 'function' && /Test$/.test(target.name)) {
testClasses.push(target);
} else if (typeof target == 'object') {
for (var i in target) {
getClassesRecurse(target[i], testClasses);
}
}
return testClasses;
}
for (var i in testClasses) {
var testObj = new testClasses[i]();
if (testObj.runTests) {
console.log('Testing: ' + testClasses[i].name, testObj);
testObj.runTests();
}
}
}
runTest();
</script>
</body>
</html>
回答1:
So, to answer my own question: it looks like I had hit "rerun" on a test and it was showing me just one test. Removing the query string and everything was good.
A suggestion to QUnit: Add a message in a big font: "Only running one test, click here to run all." =p
来源:https://stackoverflow.com/questions/13040167/qunit-wont-run-tests