Adding xpcshell tests to core modules

A few more words about xpcshell testing.

The devmo tutorial explains how to write the tests. However, the information for adding tests to the tree is perhaps not totally clear because it geared towards extension developers:

You should store your tests near the source of code you want to test. For example, imagine you want to add tests for your component in extensions/myextension/mycomponent, you will add a tests/ directory. You can store different kind of tests here (reftests etc.), and for xpcshell, you should create a unit directory and store all your javascript files inside it. Example: extensions/myextension/mycomponent/tests/unit/test_foo.js. The unit name is important because for the moment the xpcshell unit tests framework recognize only this name (especially when you want to launch a single test with check-interactive).

Then you should create a extensions/myextension/mycomponent/tests/Makefile.in which will contain XPCSHELL_TESTS = unit. Of course, in the extensions/myextension/mycomponent/Makefile.in you will add tests/ into the DIRS variable.

In practice, the work of setting up directories and makefiles may already be done. Here's some bash to list all the modules that have xpcshell unit tests and where they are located:

find ./ -name "Makefile.in" | xargs grep XPCSHELL_TESTS

If you're module has one, it's just a matter of dropping yours into the correct directory. For the most part, unit tests are found in module_name/tests/unit.

For example, here's an abridged version of the xpcom tree that shows the interface I want to test and the javascript file I use to test it:

xpcom
|-- tests
|    `--unit
|        `--test_nsIProcess.js
`-- threads
     `--nsIProcess.idl

To manually run all the tests in the unit directory:

make -C obj-ff/xpcom/tests check

Or to run just one:

make SOLO_FILE="test_nsIProcess.js" -C obj-ff/xpcom/tests check-one

 

RSS

Syndicate content