This article is in need of a technical review.
This page is not complete.
MailNews xpcshell-tests are written and run in the same manner as the core xpcshell-tests. This page describes additional resources and facilities that MailNews has developed to support the xpcshell-tests; see the core xpcshell-tests page for more information on how to develop these.
To run all xpcshell-test, run the following command in the source directory
To run a single xpcshell test use (e.g.)
./mozilla/mach xpcshell-test mailnews/news/test/unit/test_server.js
To run all xpcshell tests in a given directory, use (e.g.)
For a single test or directory, if it's inside
comm-central/mozilla/, then the path should be relative to
./mozilla/mach xpcshell-test toolkit/components/passwrdmgr
Review Requirements for new tests
When running the xpcshell-tests or check-one commands, if the test is successful and there are no reference count leaks, it will output:
TEST-PASS | /Users/moztest/comm/main/tb/mozilla/_tests/xpcshell/test_mailnewsbase/unit/test_nsIMsgFolderListener.js | test passed
If the test is successful, and there are reference count leaks, it will output something similar to:
TEST-PASS | /Users/moztest/comm/main/tb/mozilla/_tests/xpcshell/test_mailnewsbase/unit/test_nsIMsgFolderListenerLocal.js | test passed == BloatView: ALL (cumulative) LEAK STATISTICS |<----------------Class--------------->|<-----Bytes------>|<----------------Objects---------------->|<--------------References-------------->| Per-Inst Leaked Total Rem Mean StdDev Total Rem Mean StdDev 0 TOTAL 32 300 14949 6 ( 155.82 +/- 189.73) 51641 6 ( 148.25 +/- 229.91) 28 morkObject 44 132 481 3 ( 54.62 +/- 15.38) 1362 3 ( 76.49 +/- 20.87) 29 morkRowObject 56 168 97 3 ( 17.40 +/- 4.96) 127 3 ( 17.05 +/- 5.46) nsTraceRefcntImpl::DumpStatistics: 199 entries
There are some mailnews tests which are currently known to leak, these are covered by the tracking bug bug 498147 and bug 438922. The general policy is that new tests shouldn't leak, unless covered by existing bugs. If new tests really need to land with leaks, then they must have bugs covering the leak.
Test Startup and Profile Details
All MailNews xpcshell-test directories have a head_*.js file that imports mailDirService.js. This file:
- Will remove any existing files in the directory
- Will set up an
nsIDirectoryServiceProviderwhich will register
<objdir>/mozilla/_tests/mailtestas the profile directory to use for each xpcshell-tests.
- Provides a
gProfileDirglobal variable that contains a
nsIFileset up to point at
All MailNews xpcshell-tests directories should have a tail_*.js file that imports mailShutdown.js. This is done so that mailnews is shutdown correctly at the end of the unit tests which in turn ensures representative leak logs. The shutdown sequence is as follows:
- Do a cycle collection to clean up any js objects that are no longer required.
- Post the following shutdown notifications via the observer service:
- Unregisters the profile directory provider.
The MailNews xpcshell-tests have available a selection of fake servers that are used to simulate IMAP, POP3, NNTP and SMTP servers. More information is available here.
There are a variety of helper functions and objects in the files within the http://mxr.mozilla.org/comm-central/source/mailnews/test/resources/ directory. These give facilities such as:
- Alert Hooks - enabling hooking into alert dialogs.
- Asynchronuous test drivers.
- Email message generators - Generate synthetic messages.
To load these into xpcshell-tests use the command: