CINXE.COM

GTest — Firefox Source Docs documentation

<!doctype html> <html class="writer-html5" lang="en" data-content_root="../"> <head> <base href="https://firefox-source-docs.mozilla.org/gtest/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>GTest — 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=a7d3e023"> <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="Fuzzing" href="../tools/fuzzing/index.html"> <link rel="prev" title="web-platform-tests" href="../web-platform/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.1hbgkFx4Qn8.O/am=DgY/d=1/rs=AN8SPfqlmAPxwfG457BPbRXwNq39oSMGHg/m=corsproxy" data-sourceurl="https://firefox-source-docs.mozilla.org/gtest/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.1hbgkFx4Qn8.O/am=DgY/d=1/exm=corsproxy/ed=1/rs=AN8SPfqlmAPxwfG457BPbRXwNq39oSMGHg/m=phishing_protection" data-phishing-protection-enabled="false" data-forms-warning-enabled="true" data-source-url="https://firefox-source-docs.mozilla.org/gtest/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.1hbgkFx4Qn8.O/am=DgY/d=1/exm=corsproxy,phishing_protection/ed=1/rs=AN8SPfqlmAPxwfG457BPbRXwNq39oSMGHg/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/gtest/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/gtest/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/gtest/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/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/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 Platform</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/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"><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">Mochitest</a></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 current"><a class="current 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> <ul> <li class="toctree-l2"><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#integration">Integration</a></li> <li class="toctree-l2"><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#running-tests">Running tests</a> <ul> <li class="toctree-l3"><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#running-selected-tests">Running selected tests</a></li> <li class="toctree-l3"><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#configuring-gtest">Configuring GTest</a></li> </ul></li> <li class="toctree-l2"><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#debugging-a-gtest-unit-test">Debugging a GTest Unit Test</a> <ul> <li class="toctree-l3"><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#debugging-with-xcode">Debugging with Xcode</a></li> <li class="toctree-l3"><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#debugging-with-visual-studio-code">Debugging with Visual Studio Code</a></li> </ul></li> <li class="toctree-l2"><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#writing-a-gtest-unit-test">Writing a GTest Unit Test</a> <ul> <li class="toctree-l3"><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#setting-prefs-for-a-test">Setting prefs for a test</a></li> <li class="toctree-l3"><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#adding-a-test-to-the-build-system">Adding a test to the build system</a></li> <li class="toctree-l3"><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#notes">Notes</a></li> </ul></li> <li class="toctree-l2"><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#mozgtestbench">MozGTestBench</a> <ul> <li class="toctree-l3"><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#writing-a-microbench-gtest">Writing a Microbench GTest</a></li> <li class="toctree-l3"><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#sheriffing-policy">Sheriffing policy</a></li> </ul></li> </ul></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> </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">GTest</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%2Bgtest/index%26comment%3DURL%2B%3D%2Bhttps://firefox-source-docs.mozilla.org/gtest/index.html%26bug_file_loc%3Dhttps://firefox-source-docs.mozilla.org/gtest/index.html" rel="nofollow">Report an issue</a> / <a href="https://firefox--source--docs-mozilla-org.translate.goog/_sources/gtest/index.rst.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="gtest"> <h1>GTest<a class="headerlink" 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" title="Link to this heading">¶</a></h1> <p>GTest (googletest) is Google’s framework for writing C++ tests on a variety of platforms (Linux, Mac OS X, Windows, …). Based on the xUnit architecture, it supports automatic test discovery, a rich set of assertions, user-defined assertions, death tests, fatal and non-fatal failures, value- and type-parameterized tests, various options for running the tests, and XML test report generation.</p> <section id="integration"> <h2>Integration<a class="headerlink" 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#integration" title="Link to this heading">¶</a></h2> <p>GTest is run as a standard test task on Win/Mac/Linux and Android, under treeherder symbol ‘GTest’.</p> </section> <section id="running-tests"> <h2>Running tests<a class="headerlink" 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#running-tests" title="Link to this heading">¶</a></h2> <p>The Firefox build process will build GTest on supported platforms as long as you don’t disable tests in your mozconfig. However xul-gtest will only be built when tests are required to save an expensive second linking process.</p> <p>To run the unit tests use ‘mach gtest’ when invoking Gecko.</p> <section id="running-selected-tests"> <h3>Running selected tests<a class="headerlink" 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#running-selected-tests" title="Link to this heading">¶</a></h3> <p>Tests can be selected using mach. You can also use environment variables support by GTest. See <a class="reference external" href="https://translate.google.com/website?sl=pl&amp;tl=iw&amp;hl=en-GB&amp;u=https://github.com/google/googletest/blob/master/docs/advanced.md%23running-a-subset-of-the-tests">Running Test Programs: Running a Subset of the Tests</a> for more details.</p> <div class="highlight-default notranslate"> <div class="highlight"> <pre><span></span><span class="n">mach</span> <span class="n">gtest</span> <span class="n">Moz2D</span><span class="o">.*</span> </pre> </div> </div> </section> <section id="configuring-gtest"> <h3>Configuring GTest<a class="headerlink" 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#configuring-gtest" title="Link to this heading">¶</a></h3> <p>GTest can be controlled from other environment variables. See <a class="reference external" href="https://translate.google.com/website?sl=pl&amp;tl=iw&amp;hl=en-GB&amp;u=https://github.com/google/googletest/blob/master/docs/advanced.md%23running-test-programs-advanced-options">Running Test Programs: Advanced Options</a> for more details.</p> </section> </section> <section id="debugging-a-gtest-unit-test"> <h2>Debugging a GTest Unit Test<a class="headerlink" 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#debugging-a-gtest-unit-test" title="Link to this heading">¶</a></h2> <p>To debug a gtest, pass –debug to the normal command.</p> <div class="highlight-shell notranslate"> <div class="highlight"> <pre><span></span>./mach<span class="w"> </span>gtest<span class="w"> </span>--debug<span class="w"> </span><span class="o">[</span><span class="w"> </span>Prefix.Test<span class="w"> </span><span class="o">]</span> </pre> </div> </div> <p>If that doesn’t work, you can try running the firefox binary under the debugger with the MOZ_RUN_GTEST environment variable set to 1.</p> <div class="highlight-shell notranslate"> <div class="highlight"> <pre><span></span><span class="nv">MOZ_RUN_GTEST</span><span class="o">=</span><span class="m">1</span><span class="w"> </span>./mach<span class="w"> </span>run<span class="w"> </span>--debug<span class="w"> </span><span class="o">[</span>--debugger<span class="w"> </span>gdb<span class="o">]</span> </pre> </div> </div> <div class="admonition warning"> <p class="admonition-title">Warning</p> <p>Don’t forget to build + run ‘mach gtest’ to relink when using MOZ_RUN_GTEST since it’s not part of a top level build.</p> </div> <p>Note that this will load an alternate libxul - the one which has the test code built in, which resides in a gtest/subdirectory of your objdir. This gtest-enabled libxul is not built as part of the regular build, so you must ensure that it is built before running the above command. A simple way to do this is to just run “mach gtest” which will rebuild libxul and run the tests. You can also extract the commands needed to just rebuild that libxul <a class="reference external" href="https://translate.google.com/website?sl=pl&amp;tl=iw&amp;hl=en-GB&amp;u=https://hg.mozilla.org/mozilla-central/file/3673d2c688b4/python/mozbuild/mozbuild/mach_commands.py%23l486">from mach</a> and run those directly. Finally, note that you may have to run through the tests once for gdb to load all the relevant libraries and for breakpoint symbols to resolve properly.</p> <p>Note that you can debug a subset of the tests (including a single test) by using the GTEST_FILTER environment variable:</p> <div class="highlight-shell notranslate"> <div class="highlight"> <pre><span></span><span class="nv">GTEST_FILTER</span><span class="o">=</span><span class="s1">'AsyncPanZoom*'</span><span class="w"> </span><span class="nv">MOZ_RUN_GTEST</span><span class="o">=</span><span class="m">1</span><span class="w"> </span>./mach<span class="w"> </span>run<span class="w"> </span>--debug<span class="w"> </span><span class="o">[</span>--debugger<span class="w"> </span>gdb<span class="o">]</span> </pre> </div> </div> <section id="debugging-with-xcode"> <h3>Debugging with Xcode<a class="headerlink" 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#debugging-with-xcode" title="Link to this heading">¶</a></h3> <p>See <a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/contributing/debugging/debugging_on_macos.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB#debugging-on-macos"><span class="std std-ref">Debugging On macOS</span></a> for initial setup. You’ll likely want to create a separate scheme for running GTest (“Product” &gt; “Scheme” &gt; “New Scheme…”). In addition to GTEST_FILTER, Set the following environment variables:</p> <div class="highlight-default notranslate"> <div class="highlight"> <pre><span></span><span class="n">MOZ_XRE_DIR</span><span class="o">=/</span><span class="n">path</span><span class="o">-</span><span class="n">to</span><span class="o">-</span><span class="nb">object</span><span class="o">-</span><span class="n">directory</span><span class="o">/</span><span class="n">obj</span><span class="o">-</span><span class="n">ff</span><span class="o">-</span><span class="n">dbg</span><span class="o">/</span><span class="n">dist</span><span class="o">/</span><span class="nb">bin</span> <span class="n">MOZ_RUN_GTEST</span><span class="o">=</span><span class="kc">True</span> </pre> </div> </div> <p>and under the “Options” tab for the scheme, set the working directory to:</p> <div class="highlight-default notranslate"> <div class="highlight"> <pre><span></span>☑️ Use custom working directory: /path-to-object-directory/obj-ff-dbg/_tests/gtest </pre> </div> </div> </section> <section id="debugging-with-visual-studio-code"> <h3>Debugging with Visual Studio Code<a class="headerlink" 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#debugging-with-visual-studio-code" title="Link to this heading">¶</a></h3> <p>Add a configuration like this to your launch.json file (you can edit it via Run / Open Configurations):</p> <div class="highlight-default notranslate"> <div class="highlight"> <pre><span></span><span class="p">{</span> <span class="s2">"name"</span><span class="p">:</span> <span class="s2">"(gdb) Launch gtest"</span><span class="p">,</span> <span class="s2">"type"</span><span class="p">:</span> <span class="s2">"cppdbg"</span><span class="p">,</span> <span class="s2">"request"</span><span class="p">:</span> <span class="s2">"launch"</span><span class="p">,</span> <span class="s2">"program"</span><span class="p">:</span> <span class="s2">"$</span><span class="si">{workspaceFolder}</span><span class="s2">/obj-x86_64-pc-linux-gnu/dist/bin/firefox"</span><span class="p">,</span> <span class="s2">"args"</span><span class="p">:</span> <span class="p">[],</span> <span class="s2">"stopAtEntry"</span><span class="p">:</span> <span class="n">false</span><span class="p">,</span> <span class="s2">"cwd"</span><span class="p">:</span> <span class="s2">"$</span><span class="si">{workspaceFolder}</span><span class="s2">/obj-x86_64-pc-linux-gnu/_tests/gtest"</span><span class="p">,</span> <span class="s2">"environment"</span><span class="p">:</span> <span class="p">[{</span><span class="s2">"name"</span><span class="p">:</span> <span class="s2">"MOZ_RUN_GTEST"</span><span class="p">,</span> <span class="s2">"value"</span><span class="p">:</span> <span class="s2">"True"</span><span class="p">},</span> <span class="p">{</span><span class="s2">"name"</span><span class="p">:</span> <span class="s2">"GTEST_FILTER"</span><span class="p">,</span> <span class="s2">"value"</span><span class="p">:</span> <span class="s2">"AsyncPanZoom*"</span><span class="p">}],</span> <span class="s2">"externalConsole"</span><span class="p">:</span> <span class="n">false</span><span class="p">,</span> <span class="s2">"MIMode"</span><span class="p">:</span> <span class="s2">"gdb"</span><span class="p">,</span> <span class="s2">"setupCommands"</span><span class="p">:</span> <span class="p">[</span> <span class="p">{</span> <span class="s2">"description"</span><span class="p">:</span> <span class="s2">"Enable pretty-printing for gdb"</span><span class="p">,</span> <span class="s2">"text"</span><span class="p">:</span> <span class="s2">"-enable-pretty-printing"</span><span class="p">,</span> <span class="s2">"ignoreFailures"</span><span class="p">:</span> <span class="n">true</span> <span class="p">}</span> <span class="p">]</span> <span class="p">},</span> </pre> </div> </div> </section> </section> <section id="writing-a-gtest-unit-test"> <h2>Writing a GTest Unit Test<a class="headerlink" 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#writing-a-gtest-unit-test" title="Link to this heading">¶</a></h2> <p>Most of the <a class="reference external" href="https://translate.google.com/website?sl=pl&amp;tl=iw&amp;hl=en-GB&amp;u=https://github.com/google/googletest/blob/master/googletest/README.md">GTest documentation</a> will apply here. The <a class="reference external" href="https://translate.google.com/website?sl=pl&amp;tl=iw&amp;hl=en-GB&amp;u=https://github.com/google/googletest/blob/master/docs/primer.md">GTest primer</a> is a recommended read.</p> <div class="admonition warning"> <p class="admonition-title">Warning</p> <p>GTest will run tests in parallel. Don’t add unit tests that are not threadsafe, such as tests that require focus or use specific sockets.</p> </div> <div class="admonition warning"> <p class="admonition-title">Warning</p> <p>GTest will run without initializing mozilla services. Initialize and tear down any dependencies you have in your test fixtures. Avoid writing integration tests and focus on testing individual units.</p> </div> <p>See <a class="reference external" href="https://translate.google.com/website?sl=pl&amp;tl=iw&amp;hl=en-GB&amp;u=https://hg.mozilla.org/mozilla-central/rev/ed612eec41a44867a">https://hg.mozilla.org/mozilla-central/rev/ed612eec41a44867a</a> for an example of how to add a simple test.</p> <p>If you’re converting an existing C++ unit test to a GTest, <a class="reference external" href="https://translate.google.com/website?sl=pl&amp;tl=iw&amp;hl=en-GB&amp;u=https://hg.mozilla.org/mozilla-central/rev/40740cddc131">this commit</a> may serve as a useful reference.</p> <section id="setting-prefs-for-a-test"> <h3>Setting prefs for a test<a class="headerlink" 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#setting-prefs-for-a-test" title="Link to this heading">¶</a></h3> <p>If tests cover functionality that is disabled by default, you’ll have to change the relevant preferences either in the individual test:</p> <div class="highlight-default notranslate"> <div class="highlight"> <pre><span></span>bool oldPref = Preferences::GetBool(prefKey); Preferences::SetBool(prefKey, true); … // test code Preferences::SetBool(prefKey, oldPref); </pre> </div> </div> <p>or, if it applies more broadly, the change can be applied to the whole fixture (see <a class="reference external" href="https://translate.google.com/website?sl=pl&amp;tl=iw&amp;hl=en-GB&amp;u=https://github.com/google/googletest/blob/master/googletest/README.md">the GTest docs</a>, or <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/search?q%3DAutoInitializeImageLib%253A%253AAutoInitializeImageLib%26path%3D">AutoInitializeImageLib</a> as an example).</p> </section> <section id="adding-a-test-to-the-build-system"> <h3>Adding a test to the build system<a class="headerlink" 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#adding-a-test-to-the-build-system" title="Link to this heading">¶</a></h3> <p>Find a gtest directory appropriate for the module. If none exist create a directory using the following convention: ‘&lt;submodule&gt;/tests/gtest’. Create a moz.build file (in the newly created directory) with a module declaration, replacing gfxtest with a unique name, and set UNIFIED_SOURCES to contain all of the test file names.</p> <p>What we’re doing here is creating a list of source files that will be compiled and linked only against the gtest version of libxul. This will let these source files call internal xul symbols without making them part of the binary we ship to users.</p> <div class="highlight-default notranslate"> <div class="highlight"> <pre><span></span><span class="c1"># -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-</span> <span class="c1"># vim: set filetype=python:</span> <span class="c1"># This Source Code Form is subject to the terms of the Mozilla Public</span> <span class="c1"># License, v. 2.0. If a copy of the MPL was not distributed with this</span> <span class="c1"># file, you can obtain one at https://mozilla.org/MPL/2.0/.</span> <span class="n">Library</span><span class="p">(</span><span class="s1">'gfxtest'</span><span class="p">)</span> <span class="n">UNIFIED_SOURCES</span> <span class="o">=</span> <span class="p">[</span> <span class="o">&lt;</span><span class="n">ListTestFiles</span><span class="o">&gt;</span><span class="p">,</span> <span class="p">]</span> <span class="n">FINAL_LIBRARY</span> <span class="o">=</span> <span class="s1">'xul-gtest'</span> </pre> </div> </div> <p>Update ‘&lt;submodule&gt;/moz.build’ in the parent directory to build your new subdirectory in:</p> <div class="highlight-python notranslate"> <div class="highlight"> <pre><span></span><span class="n">TEST_DIRS</span> <span class="o">+=</span> <span class="p">[</span> <span class="s2">"gtest"</span><span class="p">,</span> <span class="p">]</span> </pre> </div> </div> <p>When adding tests to an existing moz.build file (it has FINAL_LIBRARY = ‘xul-gtest’), add the following. That’s it–there is no test manifest required. Your tests will be automatically registered using a static constructor.</p> <div class="highlight-python notranslate"> <div class="highlight"> <pre><span></span><span class="n">UNIFIED_SOURCES</span> <span class="o">=</span> <span class="p">[</span> <span class="s1">'TestFoo.cpp'</span><span class="p">,</span> <span class="p">]</span> </pre> </div> </div> </section> <section id="notes"> <h3>Notes<a class="headerlink" 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#notes" title="Link to this heading">¶</a></h3> <p>The include file for the class you are testing may not need to be globally exported, but it does need to be made available to the unit test you are writing. In that case, add something like this to the Makefile.in inside of the testing directory.</p> <div class="highlight-python notranslate"> <div class="highlight"> <pre><span></span><span class="n">LOCAL_INCLUDES</span> <span class="o">+=</span> <span class="p">[</span> <span class="s1">'/gfx/2d'</span><span class="p">,</span> <span class="s1">'/gfx/2d/unittest'</span><span class="p">,</span> <span class="s1">'/gfx/layers'</span><span class="p">,</span> <span class="p">]</span> </pre> </div> </div> <p>Gtests currently run from the test package under the <strong>GTest</strong> symbol on <a class="reference external" href="https://translate.google.com/website?sl=pl&amp;tl=iw&amp;hl=en-GB&amp;u=https://treeherder.mozilla.org/">Treeherder</a> if you want to verify that your test is working. Formerly they were run under the <strong>B</strong> symbol, during `make check`.</p> </section> </section> <section id="mozgtestbench"> <h2>MozGTestBench<a class="headerlink" 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#mozgtestbench" title="Link to this heading">¶</a></h2> <p>A Mozilla GTest Microbench is just a GTest that reports the test duration to perfherder. It’s an easy way to add low level performance test. Keep in mind that there’s a non-zero cost to monitoring performance test so use them sparingly. You can still perform test assertions.</p> <section id="writing-a-microbench-gtest"> <h3>Writing a Microbench GTest<a class="headerlink" 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#writing-a-microbench-gtest" title="Link to this heading">¶</a></h3> <p>Use ‘MOZ_GTEST_BENCH’ instead of ‘TEST’ to time the execution of your test. Example:</p> <div class="highlight-cpp notranslate"> <div class="highlight"> <pre><span></span><span class="cp">#include</span><span class="w"> </span><span class="cpf">"gtest/MozGTestBench.h"</span><span class="c1"> // For MOZ_GTEST_BENCH</span> <span class="p">...</span> <span class="n">MOZ_GTEST_BENCH</span><span class="p">(</span><span class="n">GfxBench</span><span class="p">,</span><span class="w"> </span><span class="n">TEST_NAME</span><span class="p">,</span><span class="w"> </span><span class="p">[]{</span> <span class="w"> </span><span class="c1">// Test to time the execution</span> <span class="p">});</span> </pre> </div> </div> <p>Make sure this file is registered with the file system using the instructions above. If everything worked correctly you should see this in the GTest log for your corresponding test:</p> <div class="highlight-js notranslate"> <div class="highlight"> <pre><span></span><span class="nx">PERFHERDER_DATA</span><span class="o">:</span><span class="w"> </span><span class="p">{</span><span class="s2">"framework"</span><span class="o">:</span><span class="w"> </span><span class="p">{</span><span class="s2">"name"</span><span class="o">:</span><span class="w"> </span><span class="s2">"platform_microbench"</span><span class="p">},</span><span class="w"> </span><span class="s2">"suites"</span><span class="o">:</span><span class="w"> </span><span class="p">[{</span><span class="s2">"name"</span><span class="o">:</span><span class="w"> </span><span class="s2">"GfxBench"</span><span class="p">,</span><span class="w"> </span><span class="s2">"subtests"</span><span class="o">:</span><span class="w"> </span><span class="p">[{</span><span class="s2">"name"</span><span class="o">:</span><span class="w"> </span><span class="s2">"CompositorSimpleTree"</span><span class="p">,</span><span class="w"> </span><span class="s2">"value"</span><span class="o">:</span><span class="w"> </span><span class="mf">252674</span><span class="p">,</span><span class="w"> </span><span class="s2">"lowerIsBetter"</span><span class="o">:</span><span class="w"> </span><span class="kc">true</span><span class="p">}]}]}</span> </pre> </div> </div> </section> <section id="sheriffing-policy"> <h3>Sheriffing policy<a class="headerlink" 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#sheriffing-policy" title="Link to this heading">¶</a></h3> <p>Microbench tests measure the speed of a very specific operation. A regression in a micro-benchmark may not lead to a user visible regression and should not be treated as strictly as a Talos regression. Large changes in microbench scores will also be expected when the code is directly modified and should be accepted if the developer intended to change that code. Micro-benchmarks however provide a framework for adding performance tests for platform code and regression tests for performance fixes. They will catch unintended regressions in code and when correlated with a Talos regression might indicate the source of the regression.</p> </section> </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/web-platform/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB" class="btn btn-neutral float-left" title="web-platform-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/tools/fuzzing/index.html?_x_tr_sl=pl&amp;_x_tr_tl=iw&amp;_x_tr_hl=en-GB" class="btn btn-neutral float-right" title="Fuzzing" 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