description: How to add your own tests for Thunderbird.

Adding Tests

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:

(Just note that these pages are Firefox-centric and include some ancient ideas and practices.)

XPCShell & Mochitest

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:

XPCShell test manifest (xpcshell.ini)

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” %}

  1. [default]
  2. prefs =
  3. calendar.timezone.local=UTC
  4. [test_firstTest.js]

{% endcode %}

The calendar preferences in line 3 is unnecessary outside of the calendar tests. Calendar tests always run in UTC.

Mochitest manifest (browser.ini)

Mochitest needs some prefs set, or automated testing will fail.

{% code title=”browser.ini” %}

  1. [default]
  2. prefs =
  3. calendar.timezone.local=UTC
  4. calendar.week.start=0
  5. ldap_2.servers.osx.description=
  6. ldap_2.servers.osx.dirType=-1
  7. ldap_2.servers.osx.uri=
  8. mail.provider.suppress_dialog_on_startup=true
  9. mail.spotlight.firstRunDone=true
  10. mail.winsearch.firstRunDone=true
  11. mailnews.start_page.override_url=about:blank
  12. mailnews.start_page.url=about:blank
  13. subsuite = thunderbird
  14. [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.

Linking to manifests

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” %}

  1. BROWSER_CHROME_MANIFESTS += [
  2. 'test/browser/browser.ini',
  3. ]
  4. XPCSHELL_TESTS_MANIFESTS += [
  5. 'test/xpcshell/xpcshell.ini',
  6. ]

{% endcode %}