From W3C Wiki
Jump to: navigation, search

This document contains some information about the Web Application WG's Test Harness which is the same test harness that is used by the HTML WG and other WGs.

Comments on this document are welcome and should be submitted to the WG's public-webapps e-mail list (archive).


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

Test cases written for WebApps' test suites should use this test harness.

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").


For examples usages see the numerous test case repositories in the web-platform-tests project.

See Also ...