Difference between revisions of "Testharness.js"

From W3C Wiki
Jump to: navigation, search
 
Line 1: Line 1:
 +
'''testharness.js''' is used for writing automatic Javascript tests.
 +
 +
== Introduction ==
 +
 
The test harness (written and maintained by James Graham) is a JavaScript file that facilitates writing test cases. More specifically, the ''boilerplate'' of the file says the following regarding its purpose:
 
The test harness (written and maintained by James Graham) is a JavaScript file that facilitates writing test cases. More specifically, the ''boilerplate'' of the file says the following regarding its purpose:
  
 
* To provide a convenient API for making common assertions
 
* To provide a convenient API for making common assertions
 
* To work both for testing synchronous and asynchronous DOM features in a way that promotes clear, robust, tests
 
* To work both for testing synchronous and asynchronous DOM features in a way that promotes clear, robust, tests
 
Test cases written for WebApps' test suites ''should'' use this test harness.
 
  
 
== Basic Usage ==
 
== Basic Usage ==

Latest revision as of 17:52, 24 January 2013

testharness.js is used for writing automatic Javascript tests.

Introduction

The test harness (written and maintained by James Graham) is a JavaScript file that facilitates writing test cases. More specifically, the boilerplate of the file says the following regarding its purpose:

  • To provide a convenient API for making common assertions
  • To work both for testing synchronous and asynchronous DOM features in a way that promotes clear, robust, tests

Basic Usage

The basic usage of the harness (testharness.js) is described in the beginning of the file.

  • To use this script file, import the script into the test document via the following script tag. Note that an expectation is that all tests must be run-able in place in the W3C's test repository. As such, an absolute path to the script file must be used and the script file will be in resources directory at the root of the repository.
    • <script src="/resources/testharness.js"></script>
    • <script src="/resources/testharnessreport.js"></script>
  • Each test can have one or more asserts. Note: some prefer a test is limited to a single assert but that is not mandatory.
  • Each test is atomic in the sense that a single test has a single result (pass/fail/timeout).
  • A test fails at the first failing assert, and the remainder of the test is (typically) not run.
  • If the file containing the tests is a HTML file with an element of id "log", this will be populated with a table containing the test results after all the tests have run.

Bug Reporting and Discussion

The discussion forum for the test harness is the W3C's cross-WG public-test-infra mail list. This list is also used to report testharness.js bugs or bugs can also be directly added to the W3C's Bugzilla: Product = Testing; Component = testharness.js (James Graham is the "default assignee"). You can also do pull requests on the testharness.js repository on GitHub.

See Also ...

  • For more information about this harness, see the documentation included at the top of the testharness.js or poke around in already existing files.
  • A nice howto: Robin Berjon's using-testharness.js