CINXE.COM

Mochitest — Firefox Source Docs documentation

<!doctype html> <html class="writer-html5" lang="en" data-content_root="../../"> <head> <base href="https://firefox-source-docs.mozilla.org/testing/mochitest-plain/index.html"> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Mochitest — Firefox Source Docs documentation</title> <link rel="stylesheet" type="text/css" href="../../_static/pygments.css?v=fa44fd50"> <link rel="stylesheet" type="text/css" href="../../_static/css/theme.css?v=19f00094"> <link rel="stylesheet" type="text/css" href="../../_static/graphviz.css?v=fd3f3429"> <link rel="stylesheet" type="text/css" href="../../_static/copybutton.css?v=76b2166b"> <link rel="stylesheet" type="text/css" href="../../_static/custom_theme.css?v=dc5ed815"> <link rel="stylesheet" type="text/css" href="../../_static/design-style.1e8bd061cd6da7fc9cf755528e8ffc24.min.css?v=0a3b3ea7"> <link rel="shortcut icon" href="../../_static/firefox.ico"><!--[if lt IE 9]> <script src="../../_static/js/html5shiv.min.js"></script> <![endif]--> <script src="../../_static/jquery.js?v=5d32c60e"></script> <script src="../../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script> <script src="../../_static/documentation_options.js?v=5929fcd5"></script> <script src="../../_static/doctools.js?v=9a2dae69"></script> <script src="../../_static/sphinx_highlight.js?v=dc90522c"></script> <script src="../../_static/clipboard.min.js?v=a7894cd8"></script> <script src="../../_static/copybutton.js?v=30646c52"></script> <script src="../../_static/design-tabs.js?v=36754332"></script> <script src="../../_static/js/theme.js"></script> <link rel="index" title="Index" href="../../genindex.html"> <link rel="search" title="Search" href="../../search.html"> <link rel="next" title="XPCShell tests" href="../xpcshell/index.html"> <link rel="prev" title="WebRender Tests" href="../webrender/index.html"> <meta http-equiv="X-Translated-By" content="Google"> <meta http-equiv="X-Translated-To" content="iw"> <script type="text/javascript" src="https://www.gstatic.com/_/translate_http/_/js/k=translate_http.tr.en_GB.tKc6KWkFf-8.O/am=gAE/d=1/rs=AN8SPfrf36LIV3DkhtRBGWFnLWWzaykPyw/m=corsproxy" data-sourceurl="https://firefox-source-docs.mozilla.org/testing/mochitest-plain/index.html"></script> <link href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200" rel="stylesheet"> <script type="text/javascript" src="https://www.gstatic.com/_/translate_http/_/js/k=translate_http.tr.en_GB.tKc6KWkFf-8.O/am=gAE/d=1/exm=corsproxy/ed=1/rs=AN8SPfrf36LIV3DkhtRBGWFnLWWzaykPyw/m=phishing_protection" data-phishing-protection-enabled="false" data-forms-warning-enabled="true" data-source-url="https://firefox-source-docs.mozilla.org/testing/mochitest-plain/index.html"></script> <meta name="robots" content="none"> </head> <body class="wy-body-for-nav"> <script type="text/javascript" src="https://www.gstatic.com/_/translate_http/_/js/k=translate_http.tr.en_GB.tKc6KWkFf-8.O/am=gAE/d=1/exm=corsproxy,phishing_protection/ed=1/rs=AN8SPfrf36LIV3DkhtRBGWFnLWWzaykPyw/m=navigationui" data-environment="prod" data-proxy-url="https://firefox--source--docs-mozilla-org.translate.goog" data-proxy-full-url="https://firefox--source--docs-mozilla-org.translate.goog/testing/mochitest-plain/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB" data-source-url="https://firefox-source-docs.mozilla.org/testing/mochitest-plain/index.html" data-source-language="pl" data-target-language="iw" data-display-language="en-GB" data-detected-source-language="" data-is-source-untranslated="false" data-source-untranslated-url="https://translate.google.com/website?sl=pl&amp;tl=iw&amp;hl=en-GB&amp;u=https://firefox-source-docs.mozilla.org/testing/mochitest-plain/index.html&amp;anno=2" data-client="tr"></script> <div class="wy-grid-for-nav"> <nav data-toggle="wy-nav-shift" class="wy-nav-side"> <div class="wy-side-scroll"> <div class="wy-side-nav-search"><a href="https://firefox--source--docs-mozilla-org.translate.goog/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB" class="icon icon-home"> Firefox Source Docs <img src="../../_static/firefox-wordmark.svg" class="logo" alt="Logo"> </a><!-- -- This code is governed by the BSD license ----> <div> <h3>Quick search</h3> <script> (function () { var cx = "dd12886298f75dbef"; var gcse = document.createElement("script"); gcse.async = true; gcse.src = "https://cse.google.com/cse.js?cx=" + cx; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(gcse, s); })(); </script><gcse:search></gcse:search> </div> </div> <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu"> <p class="caption" role="heading"><span class="caption-text">Overview</span></p> <ul> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/glossary/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">A Glossary of Common Terms</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/overview/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">A Quick Guide to Mozilla Applications</a></li> </ul> <p class="caption" role="heading"><span class="caption-text">Getting Started</span></p> <ul> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/setup/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Getting Set Up To Work On The Firefox Codebase</a></li> </ul> <p class="caption" role="heading"><span class="caption-text">Working On Firefox</span></p> <ul> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/contributing/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Working on Firefox</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/bug-mgmt/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Bug Handling</a></li> </ul> <p class="caption" role="heading"><span class="caption-text">Firefox User Guide</span></p> <ul> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/devtools-user/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Firefox DevTools User Docs</a></li> </ul> <p class="caption" role="heading"><span class="caption-text">Source Code Documentation</span></p> <ul> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/mots/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Governance</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/browser/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Firefox Front-end</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/dom/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">DOM</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/editor/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Editor</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/layout/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Style system (CSS) &amp; Layout</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/gfx/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Graphics</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/ipc/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Processes, Threads and IPC</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/devtools/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Firefox DevTools Contributor Docs</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/toolkit/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Toolkit</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/js/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">SpiderMonkey</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/jsloader/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">JS Loader</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/mobile/android/geckoview/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">GeckoView</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/mobile/android/fenix/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Fenix</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/mobile/android/focus-android/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Focus for Android</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/dom/bindings/webidl/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">WebIDL</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/modules/libpref/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">libpref</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/networking/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Networking</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/remote/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Remote Protocols</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/services/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Services</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/permissions/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Permissions</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/uriloader/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">File Handling</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/widget/cocoa/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Firefox on macOS</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/widget/windows/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Firefox on Windows</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/toolkit/components/ml/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Firefox AI Runtime</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/accessible/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Accessibility</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/media/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Media Playback</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/code-quality/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Code quality</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/writing-rust-code/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Writing Rust Code</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/rust-components/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Rust Components</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/tools/profiler/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Gecko Profiler</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/performance/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Performance</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/storage/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Database bindings (SQLite, KV, …)</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/xpcom/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">XPCOM</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/nspr/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">NSPR</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/security/nss/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Network Security Services (NSS)</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/content-security/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Web Security Checks in Gecko</a></li> </ul> <p class="caption" role="heading"><span class="caption-text">The Firefox Build System</span></p> <ul> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/mach/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Mach</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/tools/try/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Pushing to Try</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/build/buildsystem/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Build System</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/taskcluster/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Firefox CI and Taskgraph</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/tools/moztreedocs/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Managing Documentation</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/mozbuild/vendor/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Vendoring Third Party Components</a></li> </ul> <p class="caption" role="heading"><span class="caption-text">Testing &amp; Test Infrastructure</span></p> <ul class="current"> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/automated-testing/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Automated Testing</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/treeherder-try/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Understanding Treeherder Results</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/sheriffed-intermittents/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Sheriffed intermittent failures</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/tests-for-new-config/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Turning on Firefox tests for a new configuration</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/intermittent/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Avoiding intermittent tests</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/testing-policy/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Testing Policy</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/ci-configs/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Configuration Changes</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/browser-chrome/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Browser chrome mochitests</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/chrome-tests/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Chrome Tests</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/marionette/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Marionette</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/geckodriver/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">geckodriver</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/test-verification/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Test Verification</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/webrender/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">WebRender Tests</a></li> <li class="toctree-l1 current"><a class="current reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/mochitest-plain/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB#">Mochitest</a> <ul> <li class="toctree-l2"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/mochitest-plain/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB#disclaimer">DISCLAIMER</a></li> <li class="toctree-l2"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/mochitest-plain/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB#introduction">Introduction</a></li> <li class="toctree-l2"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/mochitest-plain/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB#running-tests">Running tests</a></li> <li class="toctree-l2"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/mochitest-plain/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB#running-flavors-and-subsuites">Running flavors and subsuites</a></li> <li class="toctree-l2"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/mochitest-plain/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB#debugging-individual-tests">Debugging individual tests</a></li> <li class="toctree-l2"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/mochitest-plain/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB#finding-errors">Finding errors</a></li> <li class="toctree-l2"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/mochitest-plain/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB#logging-results">Logging results</a></li> <li class="toctree-l2"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/mochitest-plain/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB#headless-mode">Headless mode</a></li> <li class="toctree-l2"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/mochitest-plain/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB#writing-tests">Writing tests</a> <ul> <li class="toctree-l3"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/mochitest-plain/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB#asynchronous-tests">Asynchronous Tests</a></li> <li class="toctree-l3"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/mochitest-plain/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB#test-functions">Test functions</a></li> <li class="toctree-l3"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/mochitest-plain/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB#helper-functions">Helper functions</a></li> <li class="toctree-l3"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/mochitest-plain/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB#adding-tests-to-the-tree">Adding tests to the tree</a></li> <li class="toctree-l3"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/mochitest-plain/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB#adding-a-new-mochitest-ini-or-chrome-ini-file">Adding a new mochitest.ini or chrome.ini file</a></li> </ul></li> <li class="toctree-l2"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/mochitest-plain/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB#faq">FAQ</a></li> </ul></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">XPCShell tests</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/tps/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">TPS</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/web-platform/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">web-platform-tests</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/gtest/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">GTest</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/tools/fuzzing/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Fuzzing</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/tools/sanitizer/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Sanitizer</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/perfdocs/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Performance Testing</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/tools/code-coverage/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Code coverage</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing-rust-code/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Testing &amp; Debugging Rust Code</a></li> </ul> <p class="caption" role="heading"><span class="caption-text">Releases &amp; Updates</span></p> <ul> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/update-infrastructure/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Mozilla Update Infrastructure</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/update-infrastructure/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB#watershed-updates">Watershed Updates</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/update-infrastructure/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB#desupport-updates">Desupport Updates</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/tools/update-verify/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Update Verify</a></li> </ul> <p class="caption" role="heading"><span class="caption-text">Localization &amp; Internationalization</span></p> <ul> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/intl/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Internationalization</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/l10n/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Localization</a></li> </ul> <p class="caption" role="heading"><span class="caption-text">Firefox and Python</span></p> <ul> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/mozbase/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">mozbase</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/python/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Using third-party Python packages</a></li> </ul> <p class="caption" role="heading"><span class="caption-text">Metrics Collected in Firefox</span></p> <ul> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/metrics/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Metrics</a></li> </ul> </div> </div> </nav> <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"> <nav class="wy-nav-top" aria-label="Mobile navigation menu"><i data-toggle="wy-nav-top" class="fa fa-bars"></i> <a href="https://firefox--source--docs-mozilla-org.translate.goog/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB">Firefox Source Docs</a> </nav> <div class="wy-nav-content"> <div class="rst-content"><!-- This Source Code Form is subject to the terms of the Mozilla Public - License, v. 2.0. If a copy of the MPL was not distributed with this file, - You can obtain one at http://mozilla.org/MPL/2.0/. --> <div role="navigation" aria-label="Page navigation"> <ul class="wy-breadcrumbs"> <li><a href="https://firefox--source--docs-mozilla-org.translate.goog/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB" class="icon icon-home" aria-label="Home"></a></li> <li class="breadcrumb-item active">Mochitest</li> <li class="wy-breadcrumbs-aside"><a href="https://translate.google.com/website?sl=pl&amp;tl=iw&amp;hl=en-GB&amp;u=https://bugzilla.mozilla.org/enter_bug.cgi?product%3DDeveloper%2BInfrastructure%26component%3DFirefox%2BSource%2BDocs%253A%2BContent%26short_desc%3DDocumentation%2Bissue%2Bon%2Btesting/mochitest-plain/index%26comment%3DURL%2B%3D%2Bhttps://firefox-source-docs.mozilla.org/testing/mochitest-plain/index.html%26bug_file_loc%3Dhttps://firefox-source-docs.mozilla.org/testing/mochitest-plain/index.html" rel="nofollow">Report an issue</a> / <a href="https://firefox--source--docs-mozilla-org.translate.goog/_sources/testing/mochitest-plain/index.md.txt?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB" rel="nofollow"> View page source</a></li> </ul> <hr> </div> <div role="main" class="document" itemscope itemtype="http://schema.org/Article"> <div itemprop="articleBody"> <section id="mochitest"> <h1>Mochitest<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/mochitest-plain/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB#mochitest" title="Link to this heading"></a></h1> <section id="disclaimer"> <h2>DISCLAIMER<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/mochitest-plain/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB#disclaimer" title="Link to this heading"></a></h2> <p>If you are testing web platform code, prefer using use a <a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/web-platform/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB"><span class="std std-doc">wpt test</span></a> (preferably upstreamable ones).</p> </section> <section id="introduction"> <h2>Introduction<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/mochitest-plain/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB#introduction" title="Link to this heading"></a></h2> <p>Mochitest is an automated testing framework built on top of the <a class="reference external" href="https://translate.google.com/website?sl=pl&amp;tl=iw&amp;hl=en-GB&amp;u=https://mochi.github.io/mochikit/">MochiKit</a> JavaScript libraries.</p> <p>Only things that can be tested using JavaScript (with chrome privileges!) can be tested with this framework. Given some creativity, that’s actually much more than you might first think, but it’s not possible to write Mochitest tests to directly test a non-scripted C++ component, for example. (Use a compiled-code test like <a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/gtest/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB"><span class="std std-doc">GTest</span></a> to do that.)</p> </section> <section id="running-tests"> <h2>Running tests<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/mochitest-plain/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB#running-tests" title="Link to this heading"></a></h2> <p>To run a single test (perhaps a new test you just added) or a subset of the entire Mochitest suite, pass a path parameter to the <code class="docutils literal notranslate"><span class="pre">mach</span></code> command.</p> <p>For example, to run only the test <code class="docutils literal notranslate"><span class="pre">test_CrossSiteXHR.html</span></code> in the Mozilla source tree, you would run this command:</p> <div class="highlight-default notranslate"> <div class="highlight"> <pre><span></span><span class="o">./</span><span class="n">mach</span> <span class="n">test</span> <span class="n">dom</span><span class="o">/</span><span class="n">security</span><span class="o">/</span><span class="n">test</span><span class="o">/</span><span class="n">cors</span><span class="o">/</span><span class="n">test_CrossSiteXHR</span><span class="o">.</span><span class="n">html</span> </pre> </div> </div> <p>To run all the tests in <code class="docutils literal notranslate"><span class="pre">dom/svg/</span></code>, this command would work:</p> <div class="highlight-default notranslate"> <div class="highlight"> <pre><span></span><span class="o">./</span><span class="n">mach</span> <span class="n">test</span> <span class="n">dom</span><span class="o">/</span><span class="n">svg</span><span class="o">/</span> </pre> </div> </div> <p>You can also pass a manifest path to run all tests on that manifest:</p> <div class="highlight-default notranslate"> <div class="highlight"> <pre><span></span><span class="o">./</span><span class="n">mach</span> <span class="n">test</span> <span class="n">dom</span><span class="o">/</span><span class="n">base</span><span class="o">/</span><span class="n">test</span><span class="o">/</span><span class="n">mochitest</span><span class="o">.</span><span class="n">ini</span> </pre> </div> </div> </section> <section id="running-flavors-and-subsuites"> <h2>Running flavors and subsuites<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/mochitest-plain/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB#running-flavors-and-subsuites" title="Link to this heading"></a></h2> <p>Flavors are variations of the default configuration used to run Mochitest. For example, a flavor might have a slightly different set of prefs set for it, a custom extension installed or even run in a completely different scope.</p> <p>The Mochitest flavors are:</p> <ul class="simple"> <li><p><strong>plain</strong> - The most basic and common Mochitest. They run in content scope, but can access certain privileged APIs with SpecialPowers.</p></li> <li><p><strong>browser</strong> - These often test the browser UI itself and run in browser window scope.</p></li> <li><p><strong>chrome</strong> - These run in chrome scope and are typically used for testing privileged JavaScript APIs. More information can be found <a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/chrome-tests/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB"><span class="std std-doc">here</span></a>.</p></li> <li><p><strong>a11y</strong> - These test the accessibility interfaces. They can be found under the top <code class="docutils literal notranslate"><span class="pre">accessible</span></code> directory and run in chrome scope. Note that these run without e10s / fission.</p></li> </ul> <p>A subsuite is similar to a flavor, except that it has an identical configuration. It is just logically separated from the “default” subsuite for display purposes. For example, devtools is a subsuite of the browser flavor. There is no difference in how these two jobs are run. It exists so that the devtools team can easily see and run their tests.</p> <p><strong>Note</strong>: There are also tags, which are similar to subsuites. Although they both are used to logically group related sets of tests, they behave differently. For example, applying a subsuite to a test removes that test from the default set, whereas, a tag does not remove it.</p> <p>By default, mach finds and runs every test in the given subdirectory no matter which flavor or subsuite it belongs to. But sometimes, you might only want to run a specific flavor or subsuite. This can be accomplished using the <code class="docutils literal notranslate"><span class="pre">--flavor</span></code> (or <code class="docutils literal notranslate"><span class="pre">-f</span></code>) and <code class="docutils literal notranslate"><span class="pre">--subsuite</span></code> options respectively. For example:</p> <div class="highlight-default notranslate"> <div class="highlight"> <pre><span></span><span class="o">./</span><span class="n">mach</span> <span class="n">mochitest</span> <span class="o">-</span><span class="n">f</span> <span class="n">plain</span> <span class="c1"># runs all plain tests</span> <span class="o">./</span><span class="n">mach</span> <span class="n">mochitest</span> <span class="o">-</span><span class="n">f</span> <span class="n">browser</span> <span class="o">--</span><span class="n">subsuite</span> <span class="n">devtools</span> <span class="c1"># runs all browser tests in the devtools subsuite</span> <span class="o">./</span><span class="n">mach</span> <span class="n">mochitest</span> <span class="o">-</span><span class="n">f</span> <span class="n">chrome</span> <span class="n">dom</span><span class="o">/</span><span class="n">indexedDB</span> <span class="c1"># runs all chrome tests in the dom/indexedDB subdirectory</span> </pre> </div> </div> <p>In many cases, it won’t be necessary to filter by flavor or subsuite as running specific directories will do it implicitly. For example running:</p> <div class="highlight-default notranslate"> <div class="highlight"> <pre><span></span><span class="o">./</span><span class="n">mach</span> <span class="n">mochitest</span> <span class="n">devtools</span><span class="o">/</span> </pre> </div> </div> <p>Is a rough equivalent to running the <code class="docutils literal notranslate"><span class="pre">devtools</span></code> subsuite. There might be situations where you might want to run tests that don’t belong to any subsuite. To do this, use:</p> <div class="highlight-default notranslate"> <div class="highlight"> <pre><span></span><span class="o">./</span><span class="n">mach</span> <span class="n">mochitest</span> <span class="o">--</span><span class="n">subsuite</span> <span class="n">default</span> </pre> </div> </div> </section> <section id="debugging-individual-tests"> <h2>Debugging individual tests<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/mochitest-plain/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB#debugging-individual-tests" title="Link to this heading"></a></h2> <p>If you need to debug an individual test, you could reload the page containing the test with the debugger attached. If attaching a debugger before the problem shows up is hard (for example, if the browser crashes as the test is loading), you can specify a debugger when you run mochitest:</p> <div class="highlight-default notranslate"> <div class="highlight"> <pre><span></span><span class="o">./</span><span class="n">mach</span> <span class="n">mochitest</span> <span class="o">--</span><span class="n">debugger</span><span class="o">=</span><span class="n">gdb</span> <span class="o">...</span> </pre> </div> </div> <p>See also the <code class="docutils literal notranslate"><span class="pre">--debugger-args</span></code> and <code class="docutils literal notranslate"><span class="pre">--debugger-interactive</span></code> arguments. You can also use the <code class="docutils literal notranslate"><span class="pre">--jsdebugger</span></code> argument to debug JavaScript.</p> </section> <section id="finding-errors"> <h2>Finding errors<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/mochitest-plain/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB#finding-errors" title="Link to this heading"></a></h2> <p>Search for the string <code class="docutils literal notranslate"><span class="pre">TEST-UNEXPECTED-FAIL</span></code> to find unexpected failures. You can also search for <code class="docutils literal notranslate"><span class="pre">SimpleTest</span> <span class="pre">FINISHED</span></code> to see the final test summary.</p> </section> <section id="logging-results"> <h2>Logging results<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/mochitest-plain/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB#logging-results" title="Link to this heading"></a></h2> <p>The output from a test run can be sent to the console and/or a file (by default the results are only displayed in the browser). There are several levels of detail to choose from. The levels are <code class="docutils literal notranslate"><span class="pre">DEBUG</span></code>, <code class="docutils literal notranslate"><span class="pre">INFO</span></code>, <code class="docutils literal notranslate"><span class="pre">WARNING</span></code>, <code class="docutils literal notranslate"><span class="pre">ERROR</span></code> and <code class="docutils literal notranslate"><span class="pre">CRITICAL</span></code>, where <code class="docutils literal notranslate"><span class="pre">DEBUG</span></code> produces the highest detail (everything), and <code class="docutils literal notranslate"><span class="pre">CRITICAL</span></code> produces the least.</p> <p>Mochitest uses structured logging. This means that you can use a set of command line arguments to configure the log output. To log to stdout using the mach formatter and log to a file in JSON format, you can use <code class="docutils literal notranslate"><span class="pre">--log-mach=-</span></code> <code class="docutils literal notranslate"><span class="pre">--log-raw=mochitest.log</span></code>. By default the file logging level for all your formatters is <code class="docutils literal notranslate"><span class="pre">INFO</span></code> but you can change this using <code class="docutils literal notranslate"><span class="pre">--log-mach-level=&lt;level&gt;</span></code>.</p> <p>To turn on logging to the console use <code class="docutils literal notranslate"><span class="pre">--console-level=&lt;level&gt;</span></code>.</p> <p>For example, to log test run output with the default (tbpl) formatter to the file <code class="docutils literal notranslate"><span class="pre">~/mochitest.log</span></code> at <code class="docutils literal notranslate"><span class="pre">DEBUG</span></code> level detail you would use:</p> <div class="highlight-default notranslate"> <div class="highlight"> <pre><span></span><span class="o">./</span><span class="n">mach</span> <span class="n">mochitest</span> <span class="o">--</span><span class="n">log</span><span class="o">-</span><span class="n">tbpl</span><span class="o">=~/</span><span class="n">mochitest</span><span class="o">.</span><span class="n">log</span> <span class="o">--</span><span class="n">log</span><span class="o">-</span><span class="n">tbpl</span><span class="o">-</span><span class="n">level</span><span class="o">=</span><span class="n">DEBUG</span> </pre> </div> </div> </section> <section id="headless-mode"> <h2>Headless mode<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/mochitest-plain/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB#headless-mode" title="Link to this heading"></a></h2> <p>The tests must run in a focused window, which effectively prevents any other user activity on the engaged computer. You can avoid this by using the <code class="docutils literal notranslate"><span class="pre">--headless</span></code> argument or <code class="docutils literal notranslate"><span class="pre">MOZ_HEADLESS=1</span></code> environment variable.</p> <div class="highlight-default notranslate"> <div class="highlight"> <pre><span></span><span class="o">./</span><span class="n">mach</span> <span class="n">mochitest</span> <span class="o">--</span><span class="n">headless</span> <span class="o">...</span> </pre> </div> </div> </section> <section id="writing-tests"> <h2>Writing tests<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/mochitest-plain/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB#writing-tests" title="Link to this heading"></a></h2> <p>A Mochitest plain test is simply an HTML or XHTML file that contains some JavaScript to test for some condition.</p> <section id="asynchronous-tests"> <h3>Asynchronous Tests<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/mochitest-plain/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB#asynchronous-tests" title="Link to this heading"></a></h3> <p>Sometimes tests involve asynchronous patterns, such as waiting for events or observers. In these cases, you need to use <code class="docutils literal notranslate"><span class="pre">add_task</span></code>:</p> <div class="highlight-js notranslate"> <div class="highlight"> <pre><span></span><span class="nx">add_task</span><span class="p">(</span><span class="k">async</span><span class="w"> </span><span class="kd">function</span><span class="w"> </span><span class="nx">my_test</span><span class="p">()</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="kd">let</span><span class="w"> </span><span class="nx">keypress</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ow">new</span><span class="w"> </span><span class="nb">Promise</span><span class="p">(...);</span> <span class="w"> </span><span class="c1">// .. simulate keypress</span> <span class="w"> </span><span class="k">await</span><span class="w"> </span><span class="nx">keypress</span><span class="p">;</span> <span class="w"> </span><span class="c1">// .. run test</span> <span class="p">});</span> </pre> </div> </div> <p>Use <code class="docutils literal notranslate"><span class="pre">add_setup()</span></code> when asynchronous test task is meant to prepare test for run. All setup tasks are executed once in order they appear prior to any test tasks.</p> <div class="highlight-js notranslate"> <div class="highlight"> <pre><span></span><span class="nx">add_setup</span><span class="p">(</span><span class="k">async</span><span class="w"> </span><span class="p">()</span><span class="w"> </span><span class="p">=&gt;</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="k">await</span><span class="w"> </span><span class="nx">clearStorage</span><span class="p">();</span> <span class="p">});</span> </pre> </div> </div> <p>Or alternatively, manually call <code class="docutils literal notranslate"><span class="pre">waitForExplicitFinish</span></code> and <code class="docutils literal notranslate"><span class="pre">finish</span></code>:</p> <div class="highlight-js notranslate"> <div class="highlight"> <pre><span></span><span class="nx">SimpleTest</span><span class="p">.</span><span class="nx">waitForExplicitFinish</span><span class="p">();</span> <span class="nx">addEventListener</span><span class="p">(</span><span class="s2">"keypress"</span><span class="p">,</span><span class="w"> </span><span class="kd">function</span><span class="p">()</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="c1">// ... run test ...</span> <span class="w"> </span><span class="nx">SimpleTest</span><span class="p">.</span><span class="nx">finish</span><span class="p">();</span> <span class="p">},</span><span class="w"> </span><span class="kc">false</span><span class="p">);</span> <span class="c1">// ... simulate key press ...</span> </pre> </div> </div> <p>If you need more time, <code class="docutils literal notranslate"><span class="pre">requestLongerTimeout(number)</span></code> can be quite useful. <code class="docutils literal notranslate"><span class="pre">requestLongerTimeout()</span></code> takes an integer factor that is a multiplier for the default 45 seconds timeout. So a factor of 2 means: “Wait for at last 90s (2*45s)”. This is really useful if you want to pause execution to do a little debugging.</p> </section> <section id="test-functions"> <h3>Test functions<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/mochitest-plain/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB#test-functions" title="Link to this heading"></a></h3> <p>Each test must contain some JavaScript that will run and tell Mochitest whether the test has passed or failed. <code class="docutils literal notranslate"><span class="pre">SimpleTest.js</span></code> provides a number of functions for the test to use, to communicate the results back to Mochitest. These include:</p> <ul class="simple"> <li><p><code class="docutils literal notranslate"><span class="pre">ok(expressionThatShouldBeTrue,</span> <span class="pre">"Description</span> <span class="pre">of</span> <span class="pre">the</span> <span class="pre">check")</span></code> – tests a value for its truthfulness</p></li> <li><p><code class="docutils literal notranslate"><span class="pre">is(actualValue,</span> <span class="pre">expectedValue,</span> <span class="pre">"Description</span> <span class="pre">of</span> <span class="pre">the</span> <span class="pre">check")</span></code> – compares two values (using Object.is)</p></li> <li><p><code class="docutils literal notranslate"><span class="pre">isnot(actualValue,</span> <span class="pre">unexpectedValue,</span> <span class="pre">"Description</span> <span class="pre">of</span> <span class="pre">the</span> <span class="pre">check")</span></code> – opposite of is()</p></li> </ul> <p>If you want to include a test for something that currently fails, don’t just comment it out! Instead, use one of the “todo” equivalents so we notice if it suddenly starts passing (at which point the test can be re-enabled):</p> <ul class="simple"> <li><p><code class="docutils literal notranslate"><span class="pre">todo(falseButShouldBeTrue,</span> <span class="pre">"Description</span> <span class="pre">of</span> <span class="pre">the</span> <span class="pre">check")</span></code></p></li> <li><p><code class="docutils literal notranslate"><span class="pre">todo_is(actualValue,</span> <span class="pre">expectedValue,</span> <span class="pre">"Description</span> <span class="pre">of</span> <span class="pre">the</span> <span class="pre">check")</span></code></p></li> <li><p><code class="docutils literal notranslate"><span class="pre">todo_isnot(actualValue,</span> <span class="pre">unexpectedValue,</span> <span class="pre">"Description</span> <span class="pre">of</span> <span class="pre">the</span> <span class="pre">check")</span></code></p></li> </ul> <p>Tests can call a function <code class="docutils literal notranslate"><span class="pre">info("Message</span> <span class="pre">string")</span></code> to write a message to the test log.</p> <p>In addition to mochitest assertions, mochitest supports the <a class="reference external" href="https://translate.google.com/website?sl=pl&amp;tl=iw&amp;hl=en-GB&amp;u=http://wiki.commonjs.org/wiki/Unit_Testing/1.1">CommonJS standard assertions</a>, like <a class="reference external" href="https://translate.google.com/website?sl=pl&amp;tl=iw&amp;hl=en-GB&amp;u=https://nodejs.org/api/assert.html%23assert">nodejs’ assert module</a> but implemented in <code class="docutils literal notranslate"><span class="pre">Assert.sys.mjs</span></code>. These are auto-imported in the browser flavor, but need to be imported manually in other flavors.</p> </section> <section id="helper-functions"> <h3>Helper functions<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/mochitest-plain/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB#helper-functions" title="Link to this heading"></a></h3> <p>Right now, useful helpers derived from MochiKit are available in <a class="reference external" href="https://translate.google.com/website?sl=pl&amp;tl=iw&amp;hl=en-GB&amp;u=https://searchfox.org/mozilla-central/source/testing/mochitest/tests/SimpleTest/SimpleTest.js"><code class="docutils literal notranslate"><span class="pre">testing/mochitest/tests/SimpleTest/SimpleTest.js</span></code></a>.</p> <p>Although all of Mochikit is available at <code class="docutils literal notranslate"><span class="pre">testing/mochitest/MochiKit</span></code>, only include files that you require to minimize test load times. <a class="reference external" href="https://translate.google.com/website?sl=pl&amp;tl=iw&amp;hl=en-GB&amp;u=https://bugzilla.mozilla.org/show_bug.cgi?id%3D367569">Bug 367569</a> added <code class="docutils literal notranslate"><span class="pre">sendChar</span></code>, <code class="docutils literal notranslate"><span class="pre">sendKey</span></code>, and <code class="docutils literal notranslate"><span class="pre">sendString</span></code> helpers. These are available in <a class="reference external" href="https://translate.google.com/website?sl=pl&amp;tl=iw&amp;hl=en-GB&amp;u=https://searchfox.org/mozilla-central/source/testing/mochitest/tests/SimpleTest/EventUtils.js"><code class="docutils literal notranslate"><span class="pre">testing/mochitest/tests/SimpleTest/EventUtils.js</span></code></a>.</p> <p>If you need to access some data files from your Mochitest, you can get an URI for them by using <code class="docutils literal notranslate"><span class="pre">SimpleTest.getTestFileURL("relative/path/to/data.file")</span></code>. Then you can eventually fetch their content by using <code class="docutils literal notranslate"><span class="pre">XMLHttpRequest</span></code> or so.</p> </section> <section id="adding-tests-to-the-tree"> <h3>Adding tests to the tree<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/mochitest-plain/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB#adding-tests-to-the-tree" title="Link to this heading"></a></h3> <p><code class="docutils literal notranslate"><span class="pre">mach</span> <span class="pre">addtest</span></code> is the preferred way to add a test to the tree:</p> <div class="highlight-default notranslate"> <div class="highlight"> <pre><span></span><span class="o">./</span><span class="n">mach</span> <span class="n">addtest</span> <span class="o">--</span><span class="n">suite</span> <span class="n">mochitest</span><span class="o">-</span><span class="p">{</span><span class="n">plain</span><span class="p">,</span><span class="n">chrome</span><span class="p">,</span><span class="n">browser</span><span class="o">-</span><span class="n">chrome</span><span class="p">}</span> <span class="n">path</span><span class="o">/</span><span class="n">to</span><span class="o">/</span><span class="n">new</span><span class="o">/</span><span class="n">test</span> </pre> </div> </div> <p>That will add the manifest entry to the relevant manifest (<code class="docutils literal notranslate"><span class="pre">mochitest.ini</span></code>, <code class="docutils literal notranslate"><span class="pre">chrome.ini</span></code>, etc. depending on the flavor) to tell the build system about your new test, as well as creating the file based on a template.</p> <div class="highlight-ini notranslate"> <div class="highlight"> <pre><span></span><span class="k">[test_new_feature.html]</span> </pre> </div> </div> <p>Optionally, you can specify metadata for your test, like whether to skip the test on certain platforms:</p> <div class="highlight-ini notranslate"> <div class="highlight"> <pre><span></span><span class="k">[test_new_feature.html]</span> <span class="na">skip-if</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">os == 'win'</span> </pre> </div> </div> <p>The <a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/build/buildsystem/test_manifests.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB"><span class="std std-doc">mochitest.ini format</span></a>, which is recognized by the parser, defines a long list of metadata.</p> </section> <section id="adding-a-new-mochitest-ini-or-chrome-ini-file"> <h3>Adding a new mochitest.ini or chrome.ini file<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/mochitest-plain/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB#adding-a-new-mochitest-ini-or-chrome-ini-file" title="Link to this heading"></a></h3> <p>If a <code class="docutils literal notranslate"><span class="pre">mochitest.ini</span></code> or <code class="docutils literal notranslate"><span class="pre">chrome.ini</span></code> file does not exist in the test directory where you want to add a test, add them and update the moz.build file in the directory for your test. For example, in <code class="docutils literal notranslate"><span class="pre">gfx/layers/moz.build</span></code>, we add these two manifest files:</p> <div class="highlight-python notranslate"> <div class="highlight"> <pre><span></span><span class="n">MOCHITEST_MANIFESTS</span> <span class="o">+=</span> <span class="p">[</span><span class="s1">'apz/test/mochitest.ini'</span><span class="p">]</span> <span class="n">MOCHITEST_CHROME_MANIFESTS</span> <span class="o">+=</span> <span class="p">[</span><span class="s1">'apz/test/chrome.ini'</span><span class="p">]</span> </pre> </div> </div><!-- TODO: This might be outdated.* ## Getting Stack Traces To get stack when Mochitest crashes: * Get a minidump_stackwalk binary for your platform from http://hg.mozilla.org/build/tools/file/tip/breakpad/ * Set the MINIDUMP_STACKWALK environment variable to point to the absolute path of the binary. If the resulting stack trace doesn't have line numbers, run `mach buildsymbols` to generate the requisite symbol files. --> </section> </section> <section id="faq"> <h2>FAQ<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/mochitest-plain/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB#faq" title="Link to this heading"></a></h2> <p>See the <a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/mochitest-plain/faq.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB"><span class="std std-doc">Mochitest FAQ page</span></a> for other features and such that you may want to use, such as SSL-enabled tests, custom http headers, async tests, leak debugging, prefs…</p> </section> </section> </div> </div> <footer> <div class="rst-footer-buttons" role="navigation" aria-label="Footer"><a href="https://firefox--source--docs-mozilla-org.translate.goog/testing/webrender/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB" class="btn btn-neutral float-left" title="WebRender Tests" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a> <a href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB" class="btn btn-neutral float-right" title="XPCShell tests" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a> </div> <hr> <div role="contentinfo"> <p></p> </div> Built with <a href="https://translate.google.com/website?sl=pl&amp;tl=iw&amp;hl=en-GB&amp;u=https://www.sphinx-doc.org/">Sphinx</a> using a <a href="https://translate.google.com/website?sl=pl&amp;tl=iw&amp;hl=en-GB&amp;u=https://github.com/readthedocs/sphinx_rtd_theme">theme</a> provided by <a href="https://translate.google.com/website?sl=pl&amp;tl=iw&amp;hl=en-GB&amp;u=https://readthedocs.org">Read the Docs</a>. </footer> </div> </div> </section> </div> <script> jQuery(function () { SphinxRtdTheme.Navigation.enable(true); }); </script> <script>function gtElInit() {var lib = new google.translate.TranslateService();lib.translatePage('pl', 'iw', function () {});}</script> <script src="https://translate.google.com/translate_a/element.js?cb=gtElInit&amp;hl=en-GB&amp;client=wt" type="text/javascript"></script> </body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10