MailNews:Xpcshell tests: Difference between revisions

Add some basic guidelines and restructure the page a bit.
(Add section with link to the list of current problems for xpcshell tests.)
(Add some basic guidelines and restructure the page a bit.)
Line 7: Line 7:
MailNews has a growing set of xpcshell tests. Developers and contributors should consider adding tests within MailNews where possible.
MailNews has a growing set of xpcshell tests. Developers and contributors should consider adding tests within MailNews where possible.


== xpcshell tests within MailNews ==
xpcshell tests can be run in a variety of different ways, the [http://developer.mozilla.org/en/docs/Writing_xpcshell-based_unit_tests devmo wiki page] describes these best.
 
== xpcshell test reporting ==
 
These currently run on the [http://tinderbox.mozilla.org/SeaMonkey/ SeaMonkey tinderboxes], and report as TUnit. Thunderbird hopes to pick running of these up soon ({{bug|422817}}).
 
== Developing xpcshell tests within MailNews ==
 
When developing new tests it is useful to look at the [http://developer.mozilla.org/en/docs/Writing_xpcshell-based_unit_tests devmo documentation for writing xpcshell-based unit tests]
 
[http://mxr.mozilla.org/seamonkey/find?text=&kind=text&string=%2Fmailnews%2F.*test_.* This list links the existing tests] that are currently within Thunderbird.
 
The review policy for tests is [[MailNews:Automated_Testing#Rules_and_Review_Policy|located here]].
 
=== MailNews xpcshell test facilities ===
 
Once {{bug|432812}} is checked in, each existing directory where tests are run will have head_*.js and tail_*.js files that will provide the following by importing core scripts:
 
* A global variable "profileDir" containing an nsIFile variable with the profile directory to use for the xpcshell tests.
* A nsIDirectoryService that points at the profileDir and provides the necessary facilities to use profile-related directories, e.g. NS_GetSystemDirectory("MailD", ...).
* Automatic cleanup of the profile directory
** This is important so that the results of one test do not affect the results of another and the redundant data gets deleted (for developers running tests).
 
== Guidelines for new tests ==


xpcshell tests can be run in a variety of different ways, the [http://developer.mozilla.org/en/docs/Writing_xpcshell-based_unit_tests devmo wiki page] describes these best.
These guidelines are intended to provide some level of consistency across the MailNews tests.


When developing new tests it is useful to look at cumentation for writing xpcshell-based unit tests]
=== New Directories for tests ===
* [http://mxr.mozilla.org/seamonkey/find?text=&kind=text&string=%2Fmailnews%2F.*test_.* existing tests] and also the various support frameworks that have been written:


* [http://mxr.mozilla.org/seamonkey/source/mailnews/test/resources/mailDirService.js mailDirService.js]
* New directories should be created as test/unit under whichever directory they apply, e.g. tests directly relating to the address book go into mailnews/addrbook/test/unit.
** Provides: an nsIDirectoryServiceProvider implementation which ensures that the user "profile" directory is defined for xpcshell test implementations.
* All new directories should have a head_*.js and a tail_*.js file, these should import some of the core mailnews scripts.
** "Profile" Directory exists in the directory of the executable, it is called "mailtest"
** ''These changes haven't been checked in yet, see {{bug|432812}}''
** Can be imported via [http://bonsai.mozilla.org/cvsblame.cgi?file=/mozilla/mailnews/compose/test/unit/test_nsMsgCompose1.js&rev=1.4&mark=6 do_import_script]
** Should be used to provide a profile directory for all MailNews tests.
* [http://mxr.mozilla.org/seamonkey/source/mailnews/addrbook/test/resources/abSetup.js abSetup.js]
** Provides: Initial setup information for the default address books
* [http://mxr.mozilla.org/seamonkey/source/mailnews/addrbook/test/resources/abCleanup.js abCleanup.js]
** Provides: cleanup() function used to correctly close down all address books and remove the created files.
** Notes: release temporary variables before this function so that the garbage collector can clean up nicely (otherwise windows tests may break).


== xpcshell test reporting ==
=== New Tests ===


These currently run on the [http://tinderbox.mozilla.org/SeaMonkey/ SeaMonkey tinderboxes], and report as TUnit. Thunderbird hopes to pick running of these up soon ({{bug|422817}}).
* The test name should be relevant to the class/action the bug is testing, or the bug number of the bug it is checking that it fixes.
* Where the profile directory is required, use profileDir that is automatically created in [http://mxr.mozilla.org/seamonkey/source/mailnews/test/resources/mailDirService.js mailDirService.js]


== Coming soon ==
== Coming soon ==
canmove, Confirmed users, Bureaucrats and Sysops emeriti
3,627

edits