mozdev.org

xpunit

resources:
What's New
  • News item goes here
  • More news items go here
  • mozdev.org
Other Stuff
  • stuff goes here
  • more stuff goes here
XPUNIT

This is a working unit test framework for mozilla. It has been developed to allow XP (Extreme Programming) process for our mozilla based abstract project.

We use it in the following way:

1. Framework's shared library and 'xpt' file are placed in 'components' folder of the application to be tested. The application here can be any gecko-1.9a6 and upper application - firefox, thunderbird, you name it. Installing as an extension will also work.

2. Unit tests are XPCOM components that implement 'nsITest' interface. That interface is basically just a 'test()' method. Components may be written in any language (C++, JavaScript, ...).

3. Components are organized into a single root tree. Non-leaf components implement 'nsIUTF8StringEnumerator' to report a list of subtrees. When that is done, they are also installed. This feature allows many small independent test components to be bundled.

4. For all js components and XUL, js, XBL chrome files, 'file:///' and 'chrome://' url are mapped to locations of source files in the source tree where the tested project is built and installed from. The map of abstract project is an example.

In 'file:///' urls only file-for-file mapping is possible. 'chrome://' urls may be mapped dir-for-dir. If one mapped dir is a part of another, more specific definition will have a priority.

The framework is completely functional without this step. However, it allows to fully employ IDE by making it open source files on the line where error/failure occurs. This saves GREAT amount of efforts. The map should go to the chrome.

5. Add preference with key 'cxxunit.firstTest' and value of the root test contract ID. Add preference with key 'cxxunit.fileMap' and value of chrome url of the file map mentioned above.

6. Run tested application with '--test' command line option. We do it for the makefile on every build.

In addition to running the test suit and reporting its errors and failures, automagically all invoked XUL is validated and all js messages are logged.

Tests may execute non-continuosly. This is important if a test causes asynchronous operation like loading a XUL or web page. Such behavior can be achieved by setting 'watchWindow' or calling 'armTimer'. The test must implement 'nsIWindowListener' and 'nsITimerCallback' respectively.

We are building this component as a part of xulapp against installed xulrunner and only on linux. If someone could help us with a mozilla tree style Makefile, we would be most grateful.

The xpunit project can be contacted through the mailing list or the member list.
Copyright © 2000-2017. All rights reserved. Terms of Use & Privacy Policy.