SoftwareTesting:Tools:jsUnit: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
No edit summary
 
Line 1: Line 1:
* example jsunit-based tests ([http://people.mozilla.com/~davel/jsunit/ davel's examples])
** urls in test suite pages are resolved relative to the url of the test runner page, not the url of the test suite page
** can we use chrome urls (with appropriate manifest files) to access the jsunit core js files in a path-independent manner?  this means we just have to worry about the test runner page and the test suite/case pages.
** this is only a problem for packaging jsunit-based tests in our tree so that they point to the same core jsunit files
=Description=
=Description=
[http://www.jsunit.net/ jsUnit] is a fairly mature harness for in-browser testing.  We can easily use it to run tests that can run as content
[http://www.jsunit.net/ jsUnit] is a fairly mature harness for in-browser testing.  We can easily use it to run tests that can run as content
Line 14: Line 10:
# use the file picker to select the test you just wrote
# use the file picker to select the test you just wrote
# run the test
# run the test
==Example==
==Simple Example==
dom_3348.html: tagName of HTML element should give tag in upper case (bug 3348)
dom_3348.html: tagName of HTML element should give tag in upper case (bug 3348)
<pre>
<pre>
Line 42: Line 38:
===Output===
===Output===
the test passes
the test passes
==Example using events==
dom_338679.html - DOMAttrModified event should not report new value as prevValue for style changes
* note the use of the <tt>setUpPage</tt> function, and setting <tt>setUpPageStatus</tt> to 'complete' when it is ok to run the test assertions
<pre>
<!DOCTYPE html>
<title>Testcase bug 338679</title>
<script language="javascript" src="app/jsUnitCore.js"></script>
<script>
function setUpPage() {
    with (document.getElementById("out")) {
        addEventListener("DOMAttrModified", attr_modified, false)
        style.width = "auto"
    }
}
function attr_modified(ev) {
    this.textContent = "Previous:\t" + ev.prevValue + "\nNew:\t\t" + ev.newValue;
    setUpPageStatus = 'complete'
}
function testBug338679() {
assertEquals("Previous:\twidth: 20em;\nNew:\t\twidth: auto;",document.getElementById("out").textContent);
}
</script>
<dl>
<dt>Actual result:</dt>
<dd>
    <pre id="out" style="width: 20em">
    &lt;/pre>
</dd>
<dt>Expected result:</dt>
<dd>
    <pre>
Previous:    width: 20em;
New:        width: auto;
    &lt;/pre>
</dd>
</dl>
</pre>
==Other Examples==
* example jsunit-based tests ([http://people.mozilla.com/~davel/jsunit/ davel's examples])
=Comments=
=Comments=
* jsUnit also supports test suites.
* jsUnit also supports test suites.
** paths for files in addTestPage() are evaluated relative to the testRunner page, not the test suite page
** paths for files in addTestPage() are evaluated relative to the testRunner page, not the test suite page
=To do list=
=To do list=
* resolve how this should be checked in / referenced from the tree
** check in to tree?
** make accessible via resource: or chrome: url?
** package as an extension?
*** a wrapper extension that takes as config input the url or directory where the jsunit files live?
* make it easier to detect pass/fail status from an automated invocation harness
** add test runner that reports pass/fail via dump, log, or write to file
* convert, or use as a base, to run tests with chrome privileges
** need to break dependency on running in a browser window - see [http://lxr.mozilla.org/mozilla/source/toolkit/mozapps/update/src/testnsUpdateService.js here] for a quick attempt to do so
* convert, use as base, or merge with xpcshell-simple harness?
[[Category:SoftwareTesting]]
[[Category:SoftwareTesting]]
201

edits

Navigation menu