This article is in need of a technical review.
The Mochitest framework is part of the Mozilla build system, therefore, the simplest way to integrate it into your XUL application is to build your application using the build system. Since Firefox is the currently the primary consumer of the Mochitest system, we'll need to modify and replace some of the parts.
Mochitest has changed somewhat between Mozilla 1.9.0 and Mozilla 1.9.1 development cycles. The basics are the same for each release. The variable used to determine if tests are to be created during the build changed:
Mozilla 1.9.0: MOZ_MOCHITEST
Mozilla 1.9.1: ENABLE_TESTS
Let's assume you have a XUL application pulled into a folder called
xulapp. To make the example a bit more realistic, links are provided to files used to enable Mochitests for the XUL Explorer application.
Enable test support to top-level
- xulapp/build.mk - Tell the Mozilla build system about the test harness folders. The section below is the relevant part.
ifdef ENABLE_TESTS tier_testharness_dirs += \ testing/mochitest \ xulapp/tests \ $(NULL) endif
Add test runner script and support harness and overlay to the application
These files can be added without making any changes. They are the minimum needed to host the test environment in your application.
- xulapp/tests/Makefile.in - Copies the harness and overlay into the testing folder. Also pre-processes the
- xulapp/tests/app-harness.xul - Hosts the test system, providing the UI window to launch tests and review results.
- xulapp/tests/app-overlay.xul - Injects the harness into the application.
- xulapp/tests/runtests.py.in - Test runner script used to launch the application under test.
Add individual test scripts
Test scripts can be placed anywhere in your source tree. Make sure your makefiles are setup to copy the test scripts into the testing folder.
- xulapp/chrome/Makefile.in - Tell the build system to look in the
xulapp/chrome/testfolder to find our test scripts. The section below is the relevant part.
ifdef ENABLE_TESTS DIRS += tests endif
- xulapp/chrome/tests/Makefile.in - Copies the test script int the testing folder. Note that we are copying a chrome test.
- xulapp/chrome/tests/test_mainui.xul - Actual chrome test script.