Thu 9 Sep 2010
In honour of the Mozilla QA Haiku list:
Current tests are odd
Use jUnit for output
Many tools are free
Thu 9 Sep 2010
In honour of the Mozilla QA Haiku list:
Current tests are odd
Use jUnit for output
Many tools are free
Tue 7 Sep 2010
I'm currently re-writing a Thunderbird plugin – and in the last few years have caught the unit-testing and test driven development bug… So, how do I make my life easy by integrating Hudson and Thunderbird?
It turned out to be suprisingly difficult, here's lots of instructions plus a download.
First job was to find a javascript interpreter and unittest framework:
So xpcshell it is (believe me – that took much longer to research than you took to read it!).
You need to compile a mozilla thunderbird package on your hudson server to get access to xpcshell. These instructions are boiled down from Simple Thunderbird build. Note that my version does not have debug enabled – this is deliberate and important.
apt-get build-dep thunderbird apt-get install mercurial libasound2-dev libcurl4-openssl-dev libnotify-dev libiw-dev autoconf2.13 mkdir -pf /opt/kits/thunderbird cd /opt/kits/thunderbird # this takes a minute or two hg clone http://hg.mozilla.org/releases/comm-1.9.2/ cd comm-1.9.2 # this takes several minutes python client.py checkout # edit/create .mozconfig and enter mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/objdir-tb mk_add_options MOZ_MAKE_FLAGS="-j4" ac_add_options --enable-application=mail # this takes ages, 2hrs on an EC2 m1.small! Come back tomorrow... make -f client.mk
runxpcshelltests.py has a very non-standard output format. I've implemented a set of plugins for TAP and jUnit output formats – download runxpcsheltests.tgz – this is a drop-in replacement for /opt/kits/thunderbird/comm-1.9.2/mozilla/testing/xpcshell (if you've followed the build instruction above) but you can unpack it anywhere on your hudson server – for example, if you have a source directory then create a directory "scripts" and unpack the tgz file in it. This is also the reason for building mozilla without debug – if debug is enabled then xpcshell prints out various usage information that can't be trapped and excluded from the formatted test output.
Create a directory test/xpcshell in your source root and create a file all.sh in it containing the following:
#!/bin/bash D=`dirname $0` X=$D/../../scripts/xpcshell /usr/bin/python2.6 -u /opt/kits/thunderbird/comm-1.9.2/mozilla/config/pythonpath.py \ -I/opt/kits/thunderbird/comm-1.9.2/mozilla/build \ $X/runxpcshelltests.py \ --output-type=junit --no-leaklog --no-logfiles \ /opt/kits/thunderbird/comm-1.9.2/objdir-tb/mozilla/dist/bin/xpcshell \ $D
Now you can add test files to that directory, e.g. test_001_pass.js:
function run_test() {
do_check_true(true);
}
The do_check_true function effectively checks against "arg == true" so I also created a head_test_funcs.js file in that directory to add more testing functions, e.g.:
function do_check_trueish(item, stack) {
if (!stack)
stack = Components.stack.caller;
var text = item + " a true-ish value?";
if (item) {
++_passedChecks;
xpcshell_output.pass(stack, text);
} else {
do_throw(text, stack);
}
}
The last step is to integrate with hudson. Click on the Configure link in a hudson job. In the Execute Shell section add the line
trunk/test/xpcshell/all.sh > report_xpcshell.xml
In the Post-Build Actions section tick on Publish JUnit test result report and in the Test Report XMLs section enter
report_*.xml
If you're already using junit tests then you may need different output file names to suit.
Groovy! We can now do automated unit/regression testing on plugin base classes! The next step is to figure out how to provide the xul document environment and perform functional testing like Selenium does for browsers…
NB. I'd really like a Mozilla developer to pick up runxpcsheltests.tgz and drop it into the current Mozilla system – standardised test output is an item on the mozilla software testing wishlist.
Update: the mozilla team have taken this up as bug 595866.