Talk:SoftwareTesting:Tools:Simple xpcshell test harness: Difference between revisions

From MozillaWiki
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:

  1. Copy mozilla/tools/test-harness/xpcshell-simple/example to yourmoduledir/test
  2. In yourmoduledir/test/Makefile.in change DEPTH and MODULE appropriately:
    • DEPTH should be a relative path pointing to mozilla/, e.g. if you're in netwerk/test, set DEPTH = ../..
    • MODULE should have a value of form test_yourmodule.
  3. Reference the test dir in a parent makefile (yourmoduledir/Makefile.in)
  4. (Optional, but recommended) Add the new makefile to allmakefiles.sh (TODO: need more details about this)
  5. Reconfigure (e.g. with make -f client.mk configure)
  6. 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