Talk:SoftwareTesting:Tools:Simple xpcshell test harness: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
(link to Necko:UnitTests) |
||
Line 23: | Line 23: | ||
In <tt>test_*.js</tt> files you can use the objects you defined in your <tt>head_*.js</tt> files, as well as common functions for unit tests defined in [http://lxr.mozilla.org/seamonkey/source/tools/test-harness/xpcshell-simple/head.js head.js] | In <tt>test_*.js</tt> files you can use the objects you defined in your <tt>head_*.js</tt> files, as well as common functions for unit tests defined in [http://lxr.mozilla.org/seamonkey/source/tools/test-harness/xpcshell-simple/head.js head.js] | ||
''TODO: briefly document available functions here'' | ''TODO: briefly document available functions here, see [[Necko:UnitTests]]'' | ||
== Running unit tests == | == Running unit tests == |
Revision as of 20:49, 7 September 2006
attempts at documentation
This is my understanding of how xpcshell test harness works, not reviewed yet. --Nickolay 16:14, 6 September 2006 (PDT)
Creating the first test for a module
This section explains what needs to be done before creating a unit test for a module that doesn't have any tests yet:
- Copy mozilla/tools/test-harness/xpcshell-simple/example to yourmoduledir/test
- In yourmoduledir/test/Makefile.in change
DEPTH
andMODULE
appropriately:DEPTH
should be a relative path pointing to mozilla/, e.g. if you're in netwerk/test, setDEPTH = ../..
MODULE
should have a value of formtest_yourmodule
.
- Reference the test dir in a parent makefile (yourmoduledir/Makefile.in)
- (Optional, but recommended) Add the new makefile to allmakefiles.sh (TODO: need more details about this)
- Reconfigure (e.g. with make -f client.mk configure)
- make / make check in yourmodule
You're now ready to start writing unit tests themselves.
Writing unit tests
You should place your test files in yourmoduledir/test/unit. There are actually three types of files that can be put there:
- head_*.js - arbitrary JS code that gets executed before the tests are run.
- test_*.js - the actual tests.
- tail_*.js - arbitrary JS code that gets executed after the actual tests are run.
In test_*.js files you can use the objects you defined in your head_*.js files, as well as common functions for unit tests defined in head.js
TODO: briefly document available functions here, see Necko:UnitTests
Running unit tests
The unit tests can be run using make check or using test_all.sh directly:
- To use make check, cd to an appropriate directory (e.g. to run tests for a single module, go to modulepath/test) and run make check.
- When using test_all.sh, either cd to the folder with unit test files and run test_all.sh or run it from dist/bin with the directory containing the unit test files as a parameter, e.g.
bash test_all.sh test_mymodule