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

From MozillaWiki
Jump to navigation Jump to search
(link to Necko:UnitTests)
Line 4: Line 4:
== Creating the first test for a module ==
== 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:
This section explains what needs to be done before creating a unit test for a module that doesn't have any tests yet:
# Copy <tt>mozilla/tools/test-harness/xpcshell-simple/example</tt> to <tt>''yourmoduledir''/test</tt>
<ol>
# In <tt>''yourmoduledir''/test/Makefile.in</tt> change <code>DEPTH</code> and <code>MODULE</code> appropriately:
<li>Copy <tt>mozilla/tools/test-harness/xpcshell-simple/example</tt> to <tt>''yourmoduledir''/test</tt></li>
#* <code>DEPTH</code> should be a relative path pointing to <tt>mozilla/</tt>, e.g. if you're in <tt>netwerk/test</tt>, set <code>DEPTH = ../..</code>
<li>In <tt>''yourmoduledir''/test/Makefile.in</tt> change <code>DEPTH</code> and <code>MODULE</code> appropriately:</li>
#* <code>MODULE</code> should have a value of form <code>test_''yourmodule''</code>.
<ul>
# Reference the test dir in a parent makefile (<tt>''yourmoduledir''/Makefile.in</tt>)
<li><code>DEPTH</code> should be a relative path pointing to <tt>mozilla/</tt>, e.g. if you're in <tt>netwerk/test</tt>, set <code>DEPTH = ../..</code></li>
# (Optional, but recommended) Add the new makefile to [[allmakefiles.sh]] (TODO: need more details about this)
<li><code>MODULE</code> should have a value of form <code>test_''yourmodule''</code>.</li>
# Reconfigure (e.g. with <tt>make -f client.mk configure</tt>)
</ul>
# ''make'' / ''make check'' in <tt>''yourmodule''</tt>
<li>Reference the test dir in a parent makefile (<tt>''yourmoduledir''/Makefile.in</tt>):
<pre>ifdef ENABLE_TESTS
TOOL_DIRS  += test
endif</pre></li>
<li>(Optional, but recommended) Add the new makefile to [[allmakefiles.sh]] (TODO: need more details about this)</li>
<li>Reconfigure (e.g. with <tt>make -f client.mk configure</tt>)</li>
<li>''make'' / ''make check'' in <tt>''yourmodule''</tt></li>
</ol>


You're now ready to start writing unit tests themselves.
You're now ready to start writing unit tests themselves.

Revision as of 14:43, 9 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):
    ifdef ENABLE_TESTS
    TOOL_DIRS  += test
    endif
  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