Difference between revisions of "Development:Testing arbitrary scenarios with Mochitest"
(→Testing Your Scenario: even better?) |
(→Testing Your Scenario: update link for 1.9.2) |
||
Line 18: | Line 18: | ||
==Testing Your Scenario== | ==Testing Your Scenario== | ||
− | Gecko’s Mochitest test files are copied to subdirectories of <code>$OBJDIR/_tests/testing/mochitest/tests/</code>, e.g. <code>dom/</code> for DOM tests, by the build system. For sanity’s sake, you should create your own subfolder for your scenario’s files. Then place all HTML and supporting files for your test into the subfolder you just created. If you need to test cross-site interactions, see [http://mxr.mozilla.org/ | + | Gecko’s Mochitest test files are copied to subdirectories of <code>$OBJDIR/_tests/testing/mochitest/tests/</code>, e.g. <code>dom/</code> for DOM tests, by the build system. For sanity’s sake, you should create your own subfolder for your scenario’s files. Then place all HTML and supporting files for your test into the subfolder you just created. If you need to test cross-site interactions, see [http://mxr.mozilla.org/mozilla1.9.2/source/build/pgo/server-locations.txt this list] (formerly found in <code>automation.py</code>) for supported hosts. |
Be sure to set any Camino preferences that are required (Mochitest disables many Camino default preferences for automated testing purposes) and then navigate Camino to your test files using the chosen server name. For example, if you are testing the pop-up blocker on παράδειγμα.δοκιμή and your test file is <code>$OBJDIR/_tests/testing/mochitest/tests/popups/test.html</code>, navigate to http://sub1.παράδειγμα.δοκιμή/tests/popups/test.html to run your test. If you need to examine any profile files during or following the testings, remember the profile is located in <code>$OBJDIR/_tests/testing/mochitest/mochitesttestingprofile/</code>. | Be sure to set any Camino preferences that are required (Mochitest disables many Camino default preferences for automated testing purposes) and then navigate Camino to your test files using the chosen server name. For example, if you are testing the pop-up blocker on παράδειγμα.δοκιμή and your test file is <code>$OBJDIR/_tests/testing/mochitest/tests/popups/test.html</code>, navigate to http://sub1.παράδειγμα.δοκιμή/tests/popups/test.html to run your test. If you need to examine any profile files during or following the testings, remember the profile is located in <code>$OBJDIR/_tests/testing/mochitest/mochitesttestingprofile/</code>. |
Revision as of 17:24, 9 January 2011
Mozilla’s Mochitest testing framework has support for Camino in Gecko 1.9.0 and later. Mozilla Corp uses Mochitest to test a number of real-world web content behaviors and interactions in a controlled environment. Mochitest runs a web server (written in JavaScript! and run by the xpcshell) on your computer and uses Gecko’s proxy support to map that server to multiple hostnames during the test session.
Because of this architecture, it’s possible to run tests on various scenarios without having to find a live site on the Internet that behaves in the way you need to test. (As an example, rather than tracking down sites with Internationalized Domain Names (IDN) in order to see how various parts of Camino’s UI handle IDNs, you can create test pages locally and access them via one of the built-in IDN hosts.)
Enabling Mochitest
Unfortunately, Mochitest is only available when building with ac_add_options --enable-tests
in your mozconfig
. You probably want to add this option only in a debug build, as logging output is less useful in a static build; in addition, the static build breaks in Gecko 1.9.0 because of problems linking certain test binaries.
Running Mochitest
Once your --enable-tests
(re)build is complete, you run Mochitest using runtests.py
in $OBJDIR/_tests/testing/mochitest/
:
$ cd $OBJDIR/_tests/testing/mochitest/
$ python runtests.py
This launches Camino into the Mochitest harness, running from a special Mochitest profile ($OBJDIR/_tests/testing/mochitest/mochitesttestingprofile/
) which is created anew each time the Mochitest harness is launched.
Testing Your Scenario
Gecko’s Mochitest test files are copied to subdirectories of $OBJDIR/_tests/testing/mochitest/tests/
, e.g. dom/
for DOM tests, by the build system. For sanity’s sake, you should create your own subfolder for your scenario’s files. Then place all HTML and supporting files for your test into the subfolder you just created. If you need to test cross-site interactions, see this list (formerly found in automation.py
) for supported hosts.
Be sure to set any Camino preferences that are required (Mochitest disables many Camino default preferences for automated testing purposes) and then navigate Camino to your test files using the chosen server name. For example, if you are testing the pop-up blocker on παράδειγμα.δοκιμή and your test file is $OBJDIR/_tests/testing/mochitest/tests/popups/test.html
, navigate to http://sub1.παράδειγμα.δοκιμή/tests/popups/test.html to run your test. If you need to examine any profile files during or following the testings, remember the profile is located in $OBJDIR/_tests/testing/mochitest/mochitesttestingprofile/
.
There is no step 3. When you have completed your test, quit Camino. Happy testing!
Additional Resources
For more information about writing tests using advanced features of Mochitest, see the Mochitest documentation on MDC.
Mochitest test files live across the tree in tests/mochitest/
directories, with some stragglers in mozilla/testing/mochitest/tests/
.
The test harness itself lives in mozilla/testing/mochitest/
, although code in mozilla/build/pgo/
is also used (e.g. automation.py
).