Adding Tests

How to add your own tests for Thunderbird.

Generally, tests live near the code they are testing, however Mozmill tests live in two particular directories.

This document doesn't cover actually writing tests, for that see these MDN pages:

(Just note that they're 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 Mozmill tests (as in Firefox terms they are "browser-chrome" Mozmill tests), and xpcshell or unit for XPCShell tests.

A new directory needs some standard files: an ESLint configuration file if the directory is linted (and it should be), and a test manifest.

ESLint Configuration (eslintrc.js)

module.exports = {
// For XPCShell:
"extends": "plugin:mozilla/xpcshell-test",
// Or for Mochitest:
"extends": "plugin:mozilla/browser-test",
"rules": {
// If you want to name your test functions, which can be useful.
"func-names": "off",
// Automatically import globals from any head file,
// just ignore that this is set to "error". ;-)
"mozilla/import-headjs-globals": "error",

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.


Mochitest manifest (browser.ini)

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

prefs =
subsuite = thunderbird

Linking to manifests

The next thing you need to do is tell mach about your new test manifest. In the nearest file, add these lines as appropriate:


It's not really ideal to be adding new Mozmill tests. The platform is obsolete and now that Mochitest runs on Thunderbird it's preferred over Mozmill. But sometimes, you've gotta do what you've gotta do.

All Mozmill tests live in mail/test/mozmill, except for calendar tests, which live in calendar/test/mozmill. The test files themselves general live one directory deeper than that and are named test-something.js (or testSomething.js). To add a new test, put it in one of the existing directories, or if you must, create a new directory and add its name to the file mozmilltests.list.

If you add a calendar Mozmill test, you'll need to build again before you can use it.