Mozilla automated testing

  • Revision slug: Mozilla_automated_testing
  • Revision title: Mozilla automated testing
  • Revision id: 4178
  • Created:
  • Creator: mnoorenberghe
  • Is current revision? No
  • Comment link related pages; one or more formatting changes

Revision Content

Note: The previous page was largely out of date. The new page is intended as a guide to the testing frameworks at Mozilla; some of the old page should be split out to a "Running Automated Tests" page to complement the "Developing Tests" page (which itself needs to be updated).

Automated Testing at Mozilla

You've just written a feature and (hopefully!) want to test it. Or you've decided that an existing feature doesn't have enough tests and want to contribute some. But where do you start? You've looked around and found references to things like "xpcshell" or "mozmill" or "talos". What do they all do? What's the overlap? In short, where should your new tests go?

This document aims to answer that question. There's a very short summary of each framework, and a bit of Q&A to help you pick your framework. This may only narrow down your choices, however, in which case you should read more about the frameworks and/or hop on #ateam, #qa, or one of the development forums and ask questions.

Generally, you should pick the lowest-level framework that you can. If you are testing JavaScript but don't need a window, use xpcshell. If you're testing page layout, try to use reftest. The advantage is that you don't drag in a lot of other components that might have their own problems, so you can home in quickly on any bugs in what you are specifically testing.

In production

buildbot automation

These tests are found within the mozilla-central tree, along with the product code.  They are all run when a changeset is pushed to mozilla-central, mozilla-inbound, or try, with the results showing up on tbpl. They can also be run on their own.

The letters in parentheses are the abbreviations used by tbpl.

compiled-code (B)

Written in C++, compiled-code tests can test pretty much anything but are difficult to write properly. In general, this should be your last option for a new test, unless you have to test something that is not exposed to JavaScript.

xpcshell (X)

xpcshell are console JavaScript tests. There is no chrome, no content, no window. xpcshell is useful for testing low-level things, such as XPCOM components. If you don't need a window, use this. xpcshell is particularly useful for testing low-level objects that are exposed to JavaScript.

JS shell tests (J)

Tests specifically for the JavaScript engine. They test every piece of the engine.

crashtest (C)

Really simple: open a web page and see if it causes a crash. If you've found pages that crash Firefox, add a test here to make sure future versions don't experience this crash again.

reftest (R)

A reftest verifies that two web pages are rendered identically to test layout and graphics correctness, taking advantage of the fact that there is generally more than one way to achieve any given visual effect in a browser. For each test, Reftest will take two sample pages that try to produce the same effect (normally one with a simple markup, and one using more complex markup) and verify that they produce the same visual construct.

Mochitest (M)

Mochitest uses JavaScript to test features. Anything piece that has its functionality exposed in JavaScript can theoretically be tested with Mochitest. "Plain" mochitest should be used to test DOM APIs and other pieces of functionality exposed to web content (i.e. requiring no special permissions).

Mochitest-other (Moth)

Mochitest-other are mochitests with higher privileges, logically split into a few sections:

  • IPC: tests plugin APIs, particularly out-of-process plugins.
  • a11y: tests accessibility interfaces.
  • chrome: tests running with high privileges that can test a lot of the browser's functionality.  Tests that verify JavaScript interactions with chrome-level objects should go here. These tests do not exist for mobile Firefox.
  • browser-chrome: running in the scope of the browser window, this is a rough UI automation tool testing how the browser interacts with itself and with content. Since these are moving away from the rest of mochitest's functionality, they will eventually be split into their own category, "b-c". On mobile, these will be replaced by Robocop.

Talos (T)

Talos is a framework for performance testing. It is a more complicated beast than other Mozilla frameworks, but there is a development mode (docs required!), which in turn replaces the older standalone version. If you're measuring performance, Talos is the place to go.

Talos tests on buildbot are split into a few categories. Some test suites are run in several categories but with different configurations or metrics. The following are the codes as found on tbpl:

  • tp: Measures the load time of a set of test web pages taken from the Alexa top 500.
  • s: SVG rendering performance.

Desktop only:

  • c: chrome. A set of suites with chrome (i.e. the full UI) enabled.
  • di: dirty. Uses a "dirty" places.sqlite that more closely resembles that of an average user.
  • dr: Dromaeo. A suite of JavaScript performance tests.
  • n: nochrome. A set of suites with chrome disabled.

Mobile only:

  • dh: tdhtml. Measures the time to cycle through a set of DHTML test pages.
  • pn: tpan. Loads a test page and measures the time to pan to the bottom then back up to the top.
  • sp: tsspider. Runs the SunSpider benchmark test.
  • tpn: The tp suites with chrome disabled.
  • ts: Tests the startup time of Firefox by opening the browser 20 times.
  • w: twinopen. Time to open a new window.
  • z: tzoom. Loads a test page and measures the time to zoom in and out.

Mozmill

Mozmill is an extensive framework for browser automation. It is an extension with an extensive API to help you write functional tests that simulate user interactions, as well as a full unit test API. It can be used to test configurations that are difficult to simulate in buildbot automation. QA automation uses Mozmill to test localized builds, performance over time, and other scenarios.

Speedtests

SpeedTests is a framework for executing arbitrary tests, which report results via JavaScript calls, in several browsers.  Originally this framework was designed for modified versions of Microsoft's speed demos but has now been expanded to include conformance tests such as test262 and Kraken. SpeedTests are good for cross-browser comparisons when tests don't need to dig too deep into the guts of the browsers.

Peptest

Peptest measures responsiveness, how "snappy" Firefox/Thunderbird feels, by issuing alerts when the event loop is stuck for more than 50 ms. It will soon be available on try, to catch regressions in responsiveness. If you're helping to improve peppiness, consider writing some peptests to help you measure your improvements and to find future regressions.

In progress

Marionette

Marionette is a new test automation framework designed with B2G in mind but applies to all flavours of Gecko. The goal of marionette is to remotely drive actions in the test machine (ex: click a DOM element, navigate to a page, run a script in chrome space, etc.). It uses Selenium-like tests that send and receive JSON data directly to the lower layers of the browser. It will give you similar functionality as Selenium for Firefox builds, but with built in chrome support as well. Marionette has the potential to replace Mozmill and various other Gecko-specific test frameworks.

Robocop

Robocop is a framework to test the Firefox's native Android UI. It is based on the Robotium framework. You'll need this if you want to test the UI on Android.

So which do I use already?

Here's a series of questions to ask when you want to write some tests. Remember this is only a rough guide, and it may give you multiple frameworks. Try #ateam on irc.mozilla.org to get some more specific answers.

Is it low-level code?

If the functionality is exposed to JavaScript, consider xpcshell. If not, you'll probably have to use compiled-code tests.

Does it cause a crash?

If so, a crashtest could help isolate the problem. Note that this may lead to more tests once the core problem is found.

Is it a layout/graphics feature?

Reftest is your best bet, if possible.

Do you need to verify performance?

Try Talos!

Are you comparing speed or functionality between browsers?

See if you can write a Speedtest.

Want to investigate responsiveness?

Peptest provides an easy way to measure responsiveness.

Testing UI?

If it's mobile UI, look into Robocop. For desktop, try browser chrome tests, soon to be split out of Mochitest.

None of the above?

To get your tests run through buildbot, try Mochitest, or, if higher privileges are required and you don't need mobile testing, try Mochitest chrome tests.

While not in buildbot automation, Mozmill is a bigger framework that can test almost anything, on the desktop at least.

For desktop firefox or B2G, or if you just want to see the future of Gecko testing, look into the on-going Marionette project.

{{ languages( { "es": "es/Pruebas_automatizadas_de_Mozilla", "ja": "Ja/Mozilla_automated_testing" } ) }}

Revision Source

<div class="note"><strong>Note:</strong> The previous page was largely out of date. The new page is intended as a guide to the testing frameworks at Mozilla; some of the old page should be split out to a "<a href="/en/Running_automated_tests" title="Running automated tests">Running Automated Tests</a>" page to complement the "<a href="/en/Developing_Tests" title="Developing Tests">Developing Tests</a>" page (which itself needs to be updated).</div>
<h2>Automated Testing at Mozilla</h2>
<p>You've just written a feature and (hopefully!) want to test it. Or you've decided that an existing feature doesn't have enough tests and want to contribute some. But where do you start? You've looked around and found references to things like "xpcshell" or "mozmill" or "talos". What do they all do? What's the overlap? In short, where should your new tests go?</p>
<p>This document aims to answer that question. There's a very short summary of each framework, and a bit of Q&amp;A to help you pick your framework. This may only narrow down your choices, however, in which case you should read more about the frameworks and/or hop on #ateam, #qa, or one of the development forums and ask questions.</p>
<p>Generally, you should pick the lowest-level framework that you can. If you are testing JavaScript but don't need a window, use xpcshell. If you're testing page layout, try to use reftest. The advantage is that you don't drag in a lot of other components that might have their own problems, so you can home in quickly on any bugs in what you are specifically testing.</p>
<h2>In production</h2>
<h3>buildbot automation</h3>
<p>These tests are found within the mozilla-central tree, along with the product code.  They are all run when a changeset is pushed to mozilla-central, mozilla-inbound, or try, with the results showing up on <a class="external" href="http://tbpl.mozilla.org">tbpl</a>. They can also be run on their own.</p>
<p>The letters in parentheses are the abbreviations used by tbpl.</p>
<h4 id="compiledcode">compiled-code (B)</h4>
<p>Written in C++, <a class="internal" href="/en/Compiled-code_automated_tests" title="en/Compiled-code_automated_tests">compiled-code tests</a> can test pretty much anything but are difficult to write properly. In general, this should be your last option for a new test, unless you have to test something that is not exposed to JavaScript.</p>
<h4 id="xpcshell">xpcshell (X)</h4>
<p><a class="internal" href="/en/XPConnect/xpcshell" title="en/XPConnect/xpcshell">xpcshell</a> are console JavaScript tests. There is no chrome, no content, no window. xpcshell is useful for testing low-level things, such as XPCOM components. If you don't need a window, use this. xpcshell is particularly useful for testing low-level objects that <em>are</em> exposed to JavaScript.</p>
<h4 id="jsshell">JS shell tests (J)</h4>
<p>Tests specifically for the JavaScript engine. They test every piece of the engine.</p>
<h4 id="crashtest">crashtest (C)</h4>
<p>Really simple: open a web page and see if it causes a crash. If you've found pages that crash Firefox, add a test here to make sure future versions don't experience this crash again.</p>
<h4 id="reftest">reftest (R)</h4>
<p>A <a class="internal" href="/en/Creating_reftest-based_unit_tests" title="en/Creating reftest-based unit tests">reftest</a> verifies that two web pages are rendered identically to test layout and graphics correctness, taking advantage of the fact that there is generally more than one way to achieve any given visual effect in a browser. For each test, Reftest will take two sample pages that try to produce the same effect (normally one with a simple markup, and one using more complex markup) and verify that they produce the same visual construct.</p>
<h4 id="mochitest">Mochitest (M)</h4>
<p><a class="internal" href="/en/Mochitest" title="Mochitest">Mochitest</a> uses JavaScript to test features. Anything piece that has its functionality exposed in JavaScript can theoretically be tested with Mochitest. "Plain" mochitest should be used to test DOM APIs and other pieces of functionality exposed to web content (i.e. requiring no special permissions).</p>
<h4 id="mochitestother">Mochitest-other (Moth)</h4>
<p>Mochitest-other are mochitests with higher privileges, logically split into a few sections:</p>
<ul> <li>IPC: tests plugin APIs, particularly out-of-process plugins.</li> <li>a11y: tests accessibility interfaces.</li> <li>chrome: tests running with high privileges that can test a lot of the browser's functionality.  Tests that verify JavaScript interactions with chrome-level objects should go here. These tests do not exist for mobile Firefox.</li> <li>browser-chrome: running in the scope of the browser window, this is a rough UI automation tool testing how the browser interacts with itself and with content. Since these are moving away from the rest of mochitest's functionality, they will eventually be split into their own category, "b-c". On mobile, these will be replaced by <a class="link-https" href="https://wiki.mozilla.org/Auto-tools/AutoTestingGuide#Robocop">Robocop</a>.</li>
</ul>
<h4 id="talos">Talos (T)</h4>
<p><a class="link-https" href="https://wiki.mozilla.org/Auto-tools/Tools/Talos">Talos</a> is a framework for performance testing. It is a more complicated beast than other Mozilla frameworks, but there is a development mode (docs required!), which in turn replaces the older <a class="link-https" href="https://wiki.mozilla.org/StandaloneTalos#How_to_set_up_Talos_for_testing_at_home">standalone</a> version. If you're measuring performance, Talos is the place to go.</p>
<p><a class="link-https" href="https://wiki.mozilla.org/Buildbot/Talos">Talos tests on buildbot</a> are split into a few categories. Some test suites are run in several categories but with different configurations or metrics. The following are the codes as found on tbpl:</p>
<ul> <li>tp: Measures the load time of a set of test web pages taken from the Alexa top 500.</li> <li>s: SVG rendering performance.</li>
</ul>
<p>Desktop only:</p>
<ul> <li>c: chrome. A set of suites with chrome (i.e. the full UI) enabled.</li> <li>di: dirty. Uses a "dirty" places.sqlite that more closely resembles that of an average user.</li> <li>dr: <a class="link-https" href="https://wiki.mozilla.org/Dromaeo">Dromaeo</a>. A suite of JavaScript performance tests.</li> <li>n: nochrome. A set of suites with chrome disabled.</li>
</ul>
<p>Mobile only:</p>
<ul> <li>dh: tdhtml. Measures the time to cycle through a set of DHTML test pages.</li> <li>pn: tpan. Loads a test page and measures the time to pan to the bottom then back up to the top.</li> <li>sp: tsspider. Runs the SunSpider benchmark test.</li> <li>tpn: The tp suites with chrome disabled.</li> <li>ts: Tests the startup time of Firefox by opening the browser 20 times.</li> <li>w: twinopen. Time to open a new window.</li> <li>z: tzoom. Loads a test page and measures the time to zoom in and out.</li>
</ul>
<h4 id="mozmill">Mozmill</h4>
<p><a class="internal" href="/en/Mozmill" title="Mozmill">Mozmill</a> is an extensive framework for browser automation. It is an extension with an extensive API to help you write functional tests that simulate user interactions, as well as a full unit test API. It can be used to test configurations that are difficult to simulate in buildbot automation. QA automation uses Mozmill to test localized builds, performance over time, and other scenarios.</p>
<h4 id="speedtests">Speedtests</h4>
<p><a class="link-https" href="https://wiki.mozilla.org/Auto-tools/Projects/SpeedTests">SpeedTests</a> is a framework for executing arbitrary tests, which report results via JavaScript calls, in several browsers.  Originally this framework was designed for modified versions of Microsoft's <a class="external" href="http://ie.microsoft.com/testdrive/">speed demos</a> but has now been expanded to include conformance tests such as test262 and Kraken. SpeedTests are good for cross-browser comparisons when tests don't need to dig too deep into the guts of the browsers.</p>
<h4 id="peptest">Peptest</h4>
<p><a class="link-https" href="https://wiki.mozilla.org/Auto-tools/Projects/peptest">Peptest</a> measures responsiveness, how "snappy" Firefox/Thunderbird feels, by issuing alerts when the event loop is stuck for more than 50 ms. It will soon be available on try, to catch regressions in responsiveness. If you're helping to improve peppiness, consider writing some peptests to help you measure your improvements and to find future regressions.</p>
<h1>In progress</h1>
<h2 id="marionette">Marionette</h2>
<p><a class="link-https" href="https://wiki.mozilla.org/Auto-tools/Projects/Marionette">Marionette</a> is a new test automation framework designed with <a class="link-https" href="https://wiki.mozilla.org/B2G">B2G</a> in mind but applies to all flavours of Gecko. The goal of marionette is to remotely drive actions in the test machine (ex: click a DOM element, navigate to a page, run a script in chrome space, etc.). It uses Selenium-like tests that send and receive JSON data directly to the lower layers of the browser. It will give you similar functionality as Selenium for Firefox builds, but with built in chrome support as well. Marionette has the potential to replace Mozmill and various other Gecko-specific test frameworks.</p>
<h2 id="robocop">Robocop</h2>
<p><a class="link-https" href="https://wiki.mozilla.org/Auto-tools/Projects/Robocop">Robocop</a> is a framework to test the Firefox's native Android UI. It is based on the <a class="external" href="http://code.google.com/p/robotium/">Robotium</a> framework. You'll need this if you want to test the UI on Android.</p>
<h1>So which do I use already?</h1>
<p>Here's a series of questions to ask when you want to write some tests. Remember this is only a rough guide, and it may give you multiple frameworks. Try #ateam on irc.mozilla.org to get some more specific answers.</p>
<h3>Is it low-level code?</h3>
<p>If the functionality is exposed to JavaScript, consider <a class="internal" href="#xpcshell">xpcshell</a>. If not, you'll probably have to use <a class="internal" href="#compiledcode">compiled-code tests</a>.</p>
<h3>Does it cause a crash?</h3>
<p>If so, a <a class="internal" href="#crashtest">crashtest</a> could help isolate the problem. Note that this may lead to more tests once the core problem is found.</p>
<h3>Is it a layout/graphics feature?</h3>
<p><a class="internal" href="#reftest">Reftest</a> is your best bet, if possible.</p>
<h3>Do you need to verify performance?</h3>
<p>Try <a class="internal" href="#talos">Talos</a>!</p>
<h3>Are you comparing speed or functionality between browsers?</h3>
<p>See if you can write a <a class="internal" href="#speedtests">Speedtest</a>.</p>
<h3>Want to investigate responsiveness?</h3>
<p><a class="internal" href="#peptest">Peptest</a> provides an easy way to measure responsiveness.</p>
<h3>Testing UI?</h3>
<p>If it's mobile UI, look into <a class="internal" href="#robocop">Robocop</a>. For desktop, try <a class="internal" href="#mochitestother">browser chrome tests</a>, soon to be split out of Mochitest.</p>
<h3>None of the above?</h3>
<p>To get your tests run through buildbot, try <a class="internal" href="#mochitest">Mochitest</a>, or, if higher privileges are required and you don't need mobile testing, try <a class="internal" href="#mochitestother">Mochitest chrome tests</a>.</p>
<p>While not in buildbot automation, <a class="internal" href="#mozmill">Mozmill</a> is a bigger framework that can test almost anything, on the desktop at least.</p>
<p>For desktop firefox or B2G, or if you just want to see the future of Gecko testing, look into the on-going <a class="internal" href="#marionette">Marionette</a> project.</p>
<p>{{ languages( { "es": "es/Pruebas_automatizadas_de_Mozilla", "ja": "Ja/Mozilla_automated_testing" } ) }}</p>
Revert to this revision