Here are the simple guidelines for adding a build-time test:
- For now, enclose your test-related code (in the makefile) with
ifdef ENABLE_TESTS
- Run the test program from the "check" target in the makefile. ({{wiki.template('Named-source', [ "netwerk/test/Makefile.in", "example" ])}} to run the TestCookie program)
- In the test program:
- If the test fails, exit with a non-zero status and/or print the string "FAIL" to stdout
- If the test passes, exit with a zero status and don't print the string "FAIL" (bonus points for printing "PASS" :) )
Write the test so that you expect it to pass on all platforms, since if the test fails, the tree will go orange (once we've set this up - see {{template.Bug(352240)}} for status).
For example, to add an xpcshell test to a module, do the following:
- Copy {{template.Source("tools/test-harness/xpcshell-simple/example")}} to
yourmoduledir/tests_type
, where tests_type is something that describes your tests. You can of course useunit
ortest
if you're not feeling creative. - In <tt>yourmoduledir/tests_type/Makefile.in</tt> change
DEPTH
,MODULE
, andXPCSHELL_TESTS
appropriately: DEPTH
should be a relative path pointing to <tt>mozilla/</tt>, e.g. if you're in <tt>netwerk/test</tt>, setDEPTH = ../..
MODULE
should be defined totest_yourmodule
or justyourmodule
-- either will work fine.XPCSHELL_TESTS
be a list of subdirectories of the current directory which contain xpcshell tests. You can of course just use the one tests_type directory here, but if you want to subdivide your tests by functionality, separate directories is the way to go.- Reference the test dir in a parent makefile (<tt>yourmoduledir/Makefile.in</tt>):
ifdef ENABLE_TESTS DIRS += tests_type endif
- (Optional, but recommended) Add the new makefile to allmakefiles.sh (TODO: need more details about this)
- Reconfigure (e.g. with <tt>make -f client.mk configure</tt>)
- make / make check in <tt>yourmodule</tt>