description |
---|
How to add your own tests for Thunderbird. |
Generally, tests live near the code they are testing, however some old tests are in a separate test directory.
This document doesn't cover actually writing tests, for that see this page for Mochitests:
And also these pages:
- Writing xpcshell-based unit tests
- Mochitest (archived MDN content)
(Just note that these pages are Firefox-centric and include some ancient ideas and practices.)
Tests should be added to a directory near the code they are located. For example, code in mail/components/extensions
is tested by tests in mail/components/extensions/test
. Inside the test
directory is a subdirectory named after the type of test: browser
for mochitests (as in Firefox terms they are "browser-chrome" mochitests), and xpcshell
or unit
for XPCShell tests.
A new directory needs a test manifest:
The default section isn't even necessary here, but you probably want to add a head.js
file if you're going to have more than one test.
{% code title="xpcshell.ini" %}
[default]
prefs =
calendar.timezone.local=UTC
[test_firstTest.js]
{% endcode %}
The calendar preferences in line 3 is unnecessary outside of the calendar tests. Calendar tests always run in UTC.
Mochitest needs some prefs set, or automated testing will fail.
{% code title="browser.ini" %}
[default]
prefs =
calendar.timezone.local=UTC
calendar.week.start=0
ldap_2.servers.osx.description=
ldap_2.servers.osx.dirType=-1
ldap_2.servers.osx.uri=
mail.provider.suppress_dialog_on_startup=true
mail.spotlight.firstRunDone=true
mail.winsearch.firstRunDone=true
mailnews.start_page.override_url=about:blank
mailnews.start_page.url=about:blank
subsuite = thunderbird
[browser_firstTest.js]
{% endcode %}
The calendar preferences in lines 3-4 are unnecessary outside of the calendar tests. Calendar tests always run in UTC with the week starting on Sunday.
The next thing you need to do is tell mach about your new test manifest. In the nearest moz.build
file, add these lines as appropriate:
{% code title="moz.build" %}
BROWSER_CHROME_MANIFESTS += [
'test/browser/browser.ini',
]
XPCSHELL_TESTS_MANIFESTS += [
'test/xpcshell/xpcshell.ini',
]
{% endcode %}