mozilla

Revision 359259 of GTest

  • Revision slug: GTest
  • Revision title: GTest
  • Revision id: 359259
  • Created:
  • Creator: bgirard
  • Is current revision? No
  • Comment

Revision Content

GTest (googletest) is Google's framework for writing C++ tests on a variety of platforms (Linux, Mac OS X, Windows, Cygwin, Windows CE, and Symbian). Based on the xUnit architecture. 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.

Running tests

The Mozilla build process will build GTest on supported platforms if you specify 'ac_add_options --enable-gtest'. This will compile and link any GTEST_*SRCS to libxul.so. To run the unit tests specify -unittest when invoking Gecko, optionally running from a debugger.

Running selected tests

Tests can select by using the <tt>GTEST_FILTER</tt> environment variable. See Running Test Programs: Running_a_Subset_of_the_Tests for more details.

GTEST_FILTER=Moz2D.* ./firefox -unittest

Configuring GTest

GTest can be controlled from other environment variables. See Running Test Programs: Advanced Options for more details.

Writing a GTest Unit Test

Most of the GTest documentation will apply here. The GTest primer is a recommended read.

See https://hg.mozilla.org/mozilla-central/rev/351462147f91 for an example of how to add a simple test.

Adding a test to the build system

Add the following to your Makefile. That's it, there is no test manifest required. Your tests will be automatically registered using a static constructor.

GTEST_CPPSRCS = TestFoo.cpp

Revision Source

<p>GTest (googletest) is Google's framework for writing C++ tests on a variety of platforms (Linux, Mac OS X, Windows, Cygwin, Windows CE, and Symbian). Based on the xUnit architecture. 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>
<h3 id="Running_tests" name="Running_tests">Running tests</h3>
<p>The Mozilla build process will build GTest on supported platforms if you specify 'ac_add_options --enable-gtest'. This will compile and link any GTEST_*SRCS to libxul.so. To run the unit tests specify -unittest when invoking Gecko, optionally running from a debugger.</p>
<h4 id="Running_selected_tests">Running selected tests</h4>
<p>Tests can select by using the <tt>GTEST_FILTER</tt> environment variable. See <a href="http://code.google.com/p/googletest/wiki/AdvancedGuide#Running_a_Subset_of_the_Tests" title="/en-US/docs/">Running Test Programs: Running_a_Subset_of_the_Tests</a> for more details.</p>
<pre>
GTEST_FILTER=Moz2D.* ./firefox -unittest</pre>
<h4 id="Configuring_GTest">Configuring GTest</h4>
<p>GTest can be controlled from other environment variables. See <a href="https://code.google.com/p/googletest/wiki/AdvancedGuide#Running_Test_Programs:_Advanced_Options" title="/en-US/docs/">Running Test Programs: Advanced Options</a> for more details.</p>
<h3 id="Writing_a_GTest_Unit_Test">Writing a GTest Unit Test</h3>
<p>Most of the <a href="http://code.google.com/p/googletest/wiki/Documentation" title="http://code.google.com/p/googletest/wiki/Documentation">GTest documentation</a> will apply here. The <a href="http://code.google.com/p/googletest/wiki/Primer" title="http://code.google.com/p/googletest/wiki/Primer">GTest primer</a> is a recommended read.</p>
<p>See <a href="https://hg.mozilla.org/mozilla-central/rev/351462147f91" title="https://hg.mozilla.org/mozilla-central/rev/351462147f91">https://hg.mozilla.org/mozilla-central/rev/351462147f91</a> for an example of how to add a simple test.</p>
<h4>Adding a test to the build system</h4>
<p>Add the following to your Makefile. That's it, there is no test manifest required. Your tests will be automatically registered using a static constructor.</p>
<pre>
<span class="difflineplus">GTEST_CPPSRCS = TestFoo.cpp</span></pre>
Revert to this revision