SoftwareTesting:Tools:jsUnit

From MozillaWiki
Revision as of 21:29, 16 September 2006 by Davel (talk | contribs)
Jump to navigation Jump to search
  • example jsunit-based tests (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

jsUnit is a fairly mature harness for in-browser testing. We can easily use it to run tests that can run as content

How to run the test

  1. download jsunit from jsunit.net
    • I've had success playing with 2.2a11
  2. unzip the file
    • I didn't do any of the installation stuff for jsUnit Server - I just used the unpacked files as-is
  3. add your test to the jsunit directory (the one containing testRunner.html)
  4. load testRunner.html in your browser
  5. use the file picker to select the test you just wrote
  6. run the test

Example

dom_3348.html: tagName of HTML element should give tag in upper case (bug 3348)

<HTML>
<HEAD>
<script language="javascript" src="app/jsUnitCore.js"></script>

<script>
function test3348()
{
        var oForm = document.getElementById("form1");
        assertEquals("FORM", oForm.tagName);
}
</script>
</HEAD>
<BODY>


<form id="form1">
<input type="button" value="click here" onclick="buttonClick();">
</form>


</BODY>
</HTML>

Output

the test passes

Comments

  • jsUnit also supports test suites.
    • paths for files in addTestPage() are evaluated relative to the testRunner page, not the test suite page

To do list