Add AJAX Tests To Mozilla
From MDC
Have you written an AJAX framework? Would you like to make sure we don't cause problems for your code in new releases and security updates? We have a simple format that will add your AJAX framework's code to our continuous integration infrastructure. Your tests will be executing after every checkin.
Contents |
[edit] Download Our Test Scaffolding
This is nothing too complicated. It's just a file you open from your local disk or a web server, and the tests run in JavaScript. You can use any unit test code you like, but you will have add 5 or 6 lines to communicate with our automation infrastructure. Instructions below.
[edit] Open the Package
It's arranged like this:
- manifest.json (a list of html test files that need to be executed separately)
- test_FooFramework.js (this is our test page, rename this after your framework.)
- mozilla/ (our JS test scaffolding)
- YOUR FILES HERE
[edit] Add Our Small Hook Script To Your Test Pages
<!DOCTYPE HTML>
<html>
<head>
<title>Test for Foo Framework</title>
<!-- ADD THIS FILE -->
<script type="text/javascript" src="../mozilla/hooks.js"></script>
<script type="text/javascript" src="FooFramework.js"></script>
<script>
function doTests() {
Foo.assert(3==3, "test eq of 3");
Foo.assert(4==4, "test eq of 4");
Foo.finishTests();
}
</script>
</head>
<body onload="doTests();">
Test for Foo Framework File 2
</body>
</html>
[edit] Add Two Callbacks To Your Test Functions
We need to maintain coherent logging for every framework, so it's easiest for us to listen for common events. The download contained a fictional FooFramework, so let's look at what needs to be added to support that logging:
/* Demo FooFramework Containing Only Test Functions */
var Foo = {
assert: function(condition, name, diagnostic) {
var body = document.getElementsByTagName("BODY")[0];
var para = document.createElement("P");
para.innerHTML = condition + " | " + name + " | " + diagnostic;
body.appendChild(para);
// ADD THIS check for a test listener
if (window.onTestAssert) {
onTestAssert(condition, name, diagnostic);
}
},
finishTests: function() {
var body = document.getElementsByTagName("BODY")[0];
var para = document.createElement("P");
para.innerHTML = "DONE!";
body.appendChild(para);
// ADD THIS check for a test listener
if (window.onTestPageFinish) {
onTestPageFinish();
}
}
}
The onTestAssert function takes three parameters:
1.) A boolean indicating whether the assertion succeeded. 2.) The name of the test 3.) A diagnostic to print in case of error
The name and diagnostic message are optional.
The download contains these demo files for the FooFramework. That should get you started.
[edit] File A Core:Testing Bug
Use bugzilla to file a bug in Core:Testing. Use the attachment field to include a .zip or .tar.gz file containing the scaffolding and your additions.
[edit] The Fine Print
It's OK if you have lots of tests in one file, or a group of files, but each file should run unattended after opening, and tests that require full windows should open and close their own. Related files can refer to each other with relative URLs.