| 1 |
# `testharness.js` test suite |
| 2 |
|
| 3 |
The test suite for the `testharness.js` testing framework. |
| 4 |
|
| 5 |
## Executing Tests |
| 6 |
|
| 7 |
Install the following dependencies: |
| 8 |
|
| 9 |
- [Python 2.7.9+](https://www.python.org/) |
| 10 |
- [the tox Python package](https://tox.readthedocs.io/en/latest/) |
| 11 |
- [the Mozilla Firefox web browser](https://mozilla.org/firefox) |
| 12 |
- [the GeckoDriver server](https://github.com/mozilla/geckodriver) |
| 13 |
|
| 14 |
Make sure `geckodriver` can be found in your `PATH`. |
| 15 |
|
| 16 |
Currently, the tests should be run with the latest *Firefox Nightly*. In order to |
| 17 |
specify the path to Firefox Nightly, use the following command-line option: |
| 18 |
|
| 19 |
tox -- --binary=/path/to/FirefoxNightly |
| 20 |
|
| 21 |
### Automated Script |
| 22 |
|
| 23 |
Alternatively, you may run `tools/ci/ci_resources_unittest.sh`, which only depends on |
| 24 |
Python 2. The script will install other dependencies automatically and start `tox` with |
| 25 |
the correct arguments. |
| 26 |
|
| 27 |
## Authoring Tests |
| 28 |
|
| 29 |
Test cases are expressed as `.html` files located within the `tests/unit/` and |
| 30 |
`tests/functional/` sub-directories. Each test should include the |
| 31 |
`testharness.js` library with the following markup: |
| 32 |
|
| 33 |
<script src="/resources/testharness.js"></script> |
| 34 |
<script src="/resources/testharnessreport.js"></script> |
| 35 |
|
| 36 |
This should be followed by one or more `<script>` tags that interface with the |
| 37 |
`testharness.js` API in some way. For example: |
| 38 |
|
| 39 |
<script> |
| 40 |
test(function() { |
| 41 |
1 = 1; |
| 42 |
}, 'This test is expected to fail.'); |
| 43 |
</script> |
| 44 |
|
| 45 |
### Unit tests |
| 46 |
|
| 47 |
The "unit test" type allows for concisely testing the expected behavior of |
| 48 |
assertion methods. These tests may define any number of sub-tests; the |
| 49 |
acceptance criteria is simply that all tests executed pass. |
| 50 |
|
| 51 |
### Functional tests |
| 52 |
|
| 53 |
Thoroughly testing the behavior of the harness itself requires ensuring a |
| 54 |
number of considerations which cannot be verified with the "unit testing" |
| 55 |
strategy. These include: |
| 56 |
|
| 57 |
- Ensuring that some tests are not run |
| 58 |
- Ensuring conditions that cause test failures |
| 59 |
- Ensuring conditions that cause harness errors |
| 60 |
|
| 61 |
Functional tests allow for these details to be verified. Every functional test |
| 62 |
must include a summary of the expected results as a JSON string within a |
| 63 |
`<script>` tag with an `id` of `"expected"`, e.g.: |
| 64 |
|
| 65 |
<script type="text/json" id="expected"> |
| 66 |
{ |
| 67 |
"summarized_status": { |
| 68 |
"message": null, |
| 69 |
"stack": null, |
| 70 |
"status_string": "OK" |
| 71 |
}, |
| 72 |
"summarized_tests": [ |
| 73 |
{ |
| 74 |
"message": "ReferenceError: invalid assignment left-hand side", |
| 75 |
"name": "Sample HTML5 API Tests", |
| 76 |
"properties": {}, |
| 77 |
"stack": "(implementation-defined)", |
| 78 |
"status_string": "FAIL" |
| 79 |
} |
| 80 |
], |
| 81 |
"type": "complete" |
| 82 |
} |
| 83 |
</script> |