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

From MozillaWiki
Jump to navigation Jump to search
No edit summary
 
(moved to MDC)
 
(3 intermediate revisions by the same user not shown)
Line 2: Line 2:
This is my understanding of how xpcshell test harness works, not reviewed yet. --[[User:Asqueella|Nickolay]] 16:14, 6 September 2006 (PDT)
This is my understanding of how xpcshell test harness works, not reviewed yet. --[[User:Asqueella|Nickolay]] 16:14, 6 September 2006 (PDT)


== Creating the first test for a module ==
(moved to http://developer.mozilla.org/en/docs/Writing_xpcshell-based_unit_tests )
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>
# In <tt>''yourmoduledir''/test/Makefile.in</tt> change <code>DEPTH</code> and <code>MODULE</code> appropriately:
#* <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>
#* <code>MODULE</code> should have a value of form <code>test_''yourmodule''</code>.
# Reference the test dir in a parent makefile (<tt>''yourmoduledir''/Makefile.in</tt>)
# (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>
 
You're now ready to start writing unit tests themselves.
 
== Writing unit tests ==
You should place your test files in <tt>''yourmoduledir''/test/unit</tt>. There are actually three types of files that can be put there:
* <tt>head_*.js</tt> - arbitrary JS code that gets executed before the tests are run.
* <tt>test_*.js</tt> - the actual tests.
* <tt>tail_*.js</tt> - arbitrary JS code that gets executed after the actual tests are run.
 
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''
 
== Running unit tests ==
The unit tests can be run using <tt>make check</tt> or using <tt>test_all.sh</tt> directly:
* To use <tt>make check</tt>, <tt>cd</tt> to an appropriate directory (e.g. to run tests for a single module, go to <tt>''modulepath''/test</tt>) and run <tt>make check</tt>.
* When using <tt>test_all.sh</tt>, either <tt>cd</tt> to the folder with unit test files and run <tt>test_all.sh</tt> or run it from <tt>dist/bin</tt> with the directory containing the unit test files as a parameter, e.g.<pre>bash test_all.sh test_mymodule</pre>

Latest revision as of 22:32, 11 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)

(moved to http://developer.mozilla.org/en/docs/Writing_xpcshell-based_unit_tests )