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

moved to MDC
(moved to MDC)
 
(One intermediate revision 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:
<ol>
<li>Copy <tt>mozilla/tools/test-harness/xpcshell-simple/example</tt> to <tt>''yourmoduledir''/test</tt></li>
<li>In <tt>''yourmoduledir''/test/Makefile.in</tt> change <code>DEPTH</code> and <code>MODULE</code> appropriately:</li>
<ul>
<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>
<li><code>MODULE</code> should have a value of form <code>test_''yourmodule''</code>.</li>
</ul>
<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.
 
== 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, see [[Necko:UnitTests]]''
 
== 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>
Confirmed users
161

edits