Mozilla automated testing 编辑

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 "web-platform-tests" or "talos". What code, features or platforms do they all test?  Where do their feature sets overlap? In short, where should your new tests go? This document is a starting point for those who want to start to learn about Mozilla's automated testing tools and procedures. Below you'll find a short summary of each framework we use, and some questions to help you pick the framework(s) you need for your purposes.

Note: If you read this article and still have questions, try reading some of the further links provided below for more information, and hop on to the #ateam or #qa IRC channels or Mozilla Forums to ask questions.

In production

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 Treeherder. They can also be run on their own.

The tests are run on machines in a very large pool. For the most part, all tests of a particular type run on the same pool of machines, regardless of branch. One substantial exception is that try builds are performed on a pool isolated from all other builds.

Note: refer also to how test harnesses work for more information on how these tests are run.

Linting

Lint tests help to ensure better quality, less error-prone code by analysing the code with a linter.

SymbolNameFile
type
PlatformProcessEnvironmentPrivilegeWhat is tested
DesktopMobileParentChildShellBrowser
Profile
LowHigh
ESESLintJSYesYesN/ATerminalN/AJavascript is analysed for correctness.
mocha(EPM)ESLint-plugin-mozillaJSYesNoN/ATerminalN/AThe ESLint plugin rules.
f8flake8PythonYesYesN/ATerminal-N/APython analysed for style and correctness.
Wwpt lintAllYesNoN/ATerminalN/Aweb-platform-tests analysed for style and manifest correctness
android-checkstyleandroid-checkstyleJavaNoYesN/ATerminal-N/AJava analysed for coding style consistency.
android-lintandroid-lintJavaNoYesN/ATerminal-N/AJava analysed for common Android coding errors.
android-findbugsandroid-findbugsJavaNoYesN/ATerminal-N/AJava analysed for common Java coding errors.
WR(tidy)WebRender servo-tidyAllYesNoN/ATerminal-N/ACode in gfx/wr is run through servo-tidy

Functional testing

Automated Test Suites
SymbolNameFile
type
PlatformProcessEnvironmentPrivilegeWhat is tested
DesktopMobileParentChildShellBrowser
Profile
LowHigh
R(J)JS ReftestJSYesYesN/AJSShellN/AThe JavaScript engine's implementation of the JavaScript language.
R(C)CrashtestHTML
XHTML
SVG
YesYesYesContentYesYesThat pages load without crashing, asserting, or leaking.
R(R)ReftestHTML
XHTML
SVG
YesYesYesContentYesYesThat pages are rendered (and thus also layed out) correctly.
R(Rs)Reftest sanity????????
CppCompiled codeC++
Python
YesYesN/ATerminalN/ACode not exposed to JavaScript (using C++ executables), and the state of the source tree (using Python scripts).
XxpcshellJSYesYesYesAllowXPCShell
[Note 1]
AllowYesLow-level code exposed to JavaScript, such as XPCOM components.
M(oth)IPC???????Plugin APIs, particularly out-of-process plugins.
M(oth)Accessibility
(mochitest-a11y)
?Yes?YesContentYes??Accessibility interfaces.
M(1)
M(2)
M(…)
Mochitest
plain
HTML
XHTML
XUL
YesYesYesContentYesYesAllowFeatures exposed to JavaScript in web content, like DOM and other Web APIs, where the APIs do not require elevated permissions to test.
M(oth)Mochitest
chrome
HTML
XHTML
XUL
YesAllowYesContentYesYesCode requiring UI or JavaScript interactions with privileged objects.
M(bc)Mochitest
browser-chrome
JSYesYesAllowBrowserYesYesHow the browser UI interacts with itself and with content.
M(dt)Mochitest devtoolsJSYesYesAllowBrowserYesYesFirefox developer tools. Based on Mochitest browser-chrome.
M(rc)Mochitest robocopJavaYes??????Native UI of Android devices (sends events to the front end). Some use a combination of Java and JavaScript.
M(gl)Mochitest WebGL??????????
M(remote)

Mochitest Remote Protocol

JSYesNoYesAllowBrowserYes-YesFirefox Remote Protocol (Implements parts of Chrome dev-tools protocol). Based on Mochitest browser-chrome.

SM(...)
SM(pkg)

SpiderMonkey automationJS
C++
YesNoN/AJSShell-Yes-SpiderMonkey engine shell tests and JSAPI tests
Wweb-platform-testsHTML
XHTML
YesYesContentYesYesStandardized features exposed to ECMAScript in web content; tests are shared with other vendors.
Wrweb-platform-tests reftestsHTML
XHTML
YesYesContentYesYesLayout and graphic correctness for standardized features; tests are shared with other vendors
MnMarionettePythonYes??Content
Browser
?YesLarge out-of-process function integration tests and tests that do communication with multiple remote Gecko processes.
Mn-hMarionette harness testsPython--------Marionette Python Runner
JPJetpackJS????????Add-on SDK code included in Firefox. If you need help interpreting test failures or fixing bugs in the SDK code, talk to the SDK team in #jetpack.
VValgrind?Linux
only
??????Memory-related errors, such as heap block overflows/underflows, use of uninitialized memory, bad frees, and memory leaks.
FxfnFirefox UI TestsPythonYes-??Content
Browser
Yes-YesIntegration tests with a focus on the user interface and localization.
tt(c)telemetry-tests-clientPythonYesNo--Content
Browser
Yes-YesIntegration tests for the Firefox Telemetry client.
TVTest Verification (test-verify)

JS
HTML
XHTML
XUL

YesYes??????Uses other test harnesses - mochitest, reftest, xpcshell - to perform extra testing on new/modified tests.
TVw

Test Verification for wpt

(test-verify-wpt)

JS

HTML

Python

YesNo??????Uses wpt test harnesses to perform extra testing on new/modified web-platform tests.
A(...)AutophoneHTML-Yes??ContentYes??

Performance and select Unit Tests on Android devices.

android-testandroid-testJava-YesN/AN/AJavaNoN/AN/A

Run Android local unit tests.

WR(wrench)WebRender standalone testsYAML/RustYesNoN/ATerminalN/AN/AWebRender rust code (as a standalone module, with Gecko integration)
Retired Automated Test Suites
SymbolNameFile
type
PlatformProcessEnvironmentPrivilegeWhat is tested
DesktopMobileB2GParentChildShellBrowser
Profile
LowHigh
Gbgaia-build-integration?Yes??????The Gaia build system.
Gipgaia-ui-testsPythonYes??????Gaia integration. Marionette- and Python- based.
Gijgaia-integrationJSYes??????Gaia integration. Marionette- and JavaScript- based.
Ligaia-linter?Yes??????Gaia JavaScript code formatting.
MnwMarionette WebAPIJSEmul.
only
??????WebAPIs. This takes advantage of the Firefox OS emulator's ability to virtualize much of the hardware on a B2G device.

Table key

Symbol
Abbreviation for the test suite used by Treeherder. The first letter generally indicates which of the test harnesses is used to execute the test. The letter in parentheses identifies the actual test suite.
Name
Common name used when referring to the test suite.
File type
When adding a new test, you will generally create a file of this type in the source tree and then declare it in a manifest or makefile.
Platform

Most test suites are supported only on a subset of the available plaforms and operating systems. Unless otherwise noted:

  • Desktop tests run on Windows, Mac OS X, and Linux.
  • Mobile tests run on Android emulators or remotely on Android devices.
Process
  • When Parent is indicated, the test file will always run in the parent process, even when the browser is running in Electrolysis (e10s) mode.
  • When Child is indicated, the test file will run in the child process when the browser is running in Electrolysis (e10s) mode.
  • The Allow label indicates that the test has access to mechanisms to run code in the other process.
Environment
  • The JSShell and XPCShell environments are limited JavaScript execution environments with no windows or user interface (note however that XPCShell tests on Android are run within a browser window.)
  • The Java environment is a limited Java execution environments with no user interface or connection to the Gecko rendering or JavaScript environment.
  • The Content indication means that the test is run inside a content page loaded by a browser window.
  • The Browser indication means that the test is loaded in the JavaScript context of a browser XUL window.
  • The Browser Profile column indicates whether a browser profile is loaded when the test starts. The Allow label means that the test can optionally load a profile using a special command.
Privilege
Indicates whether the tests normally run with low (content) or high (chrome) JavaScript privileges. The Allow label means that the test can optionally run code in a privileged environment using a special command.

Performance testing

Talos is the framework used for performance testing. Up-to-date information on the set of tests and what they do can be found at https://wiki.mozilla.org/Performance_sheriffing/Talos/Tests

So which should I use?

Generally, you should pick the lowest-level framework that you can. If you are testing JavaScript but don't need a window, use XPCShell or even JSShell. If you're testing page layout, try to use Reftest. The advantage in lower level testing 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.

Here's a series of questions to ask about your work when you want to write some tests.

Is it low-level code?

If the functionality is exposed to JavaScript, and you don't need a window, consider XPCShell. If not, you'll probably have to use compiled-code tests, which can test pretty much anything but are difficult to write properly and are often less suitable than a domain-specific harness. In general, this should be your last option for a new test, unless you have to test something that is not exposed to JavaScript.

Does it cause a crash?

If you've found pages that crash Firefox, add a crashtest to make sure future versions don't experience this crash (assertion or leak) again. 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?

Use Talos!

Are you testing UI features?

If it's mobile UI, look into Robocop. For desktop, try browser chrome tests (soon to be split out of Mochitest), or Marionette if the application also needs to be restarted, or tested with localized builds.

Are you testing Mobile/Android?

For Mobile UI, look at Robocop. For Mobile features that are purely Java, look at android-test. There are some specific features that Mochitest or Reftest can cover. Browser-chrome tests do not run on Android. If you want to test performance, Talos runs fine with a few limitations (use the --noChrome options) and smaller cycles (e.g. 10 iterations instead of 20, etc.)

Are you doing none of the above?

  • To get your tests run through buildbot, try Mochitest, or, if higher privileges are required, try Mochitest chrome tests.
  • For Desktop Firefox, or if you just want to see the future of Gecko testing, look into the on-going Marionette project.

Need to get more data out of your tests?

Most test jobs now expose an environment variable named $MOZ_UPLOAD_DIR. If this variable is set during automated test runs, you can drop additional files into this directory, and they will be uploaded to a web server when the test finishes. The URLs to retrieve the files will be output in the test log.

Need to set preferences for test-suites?

First ask yourself if these prefs need to be enabled for all tests or just a subset of tests (e.g to enable a feature).

Setting prefs that only apply to certain tests

If the answer is the latter, try to set the pref as local to the tests that need it as possible. Here are some options:

  • If the test runs in chrome scope (e.g mochitest chrome or browser-chrome), you can use Services.prefs to set the prefs in your test's setup function. Be sure to reset the pref back to its original value during teardown!
  • Mochitest plain tests can use SpecialPowers to set prefs.
  • All variants of mochitest can set prefs in their manifests. For example, to set a pref for all tests in a manifest:

    [DEFAULT]
    prefs =
      my.awesome.pref=foo,
      my.other.awesome.pref=bar,
    [test_foo.js]
    [test_bar.js]
    
  • All variants of reftest can also set prefs in their manifests.
  • All variants of web-platform-tests can also set prefs in their manifests.

Setting prefs that apply to the entire suite

Most test suites define prefs in user.js files that live under testing/profiles. Each directory is a profile that contains a user.js file with a number of prefs defined in it. Test suites will then merge one or more of these basic profiles into their own profile at runtime. To see which profiles apply to which test suites, you can inspect testing/profiles/profiles.json. Profiles at the beginning of the list get overridden by profiles at the end of the list.

Because this system makes it hard to get an overall view of which profiles are set for any given test suite, a handy profile utility was created:

$ cd testing/profiles
$ ./profile -- --help
usage: profile [-h] {diff,sort,show,rm} ...
$ ./profile show mochitest          # prints all prefs that will be set in mochitest
$ ./profile diff mochitest reftest  # prints differences between the mochitest and reftest suites

Note: JS engine tests do not use testing/profiles yet, instead set prefs here.

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).

Also see the "Continuous Integration" page.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:74 次

字数:64591

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文