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.
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
GTest can be controlled from other environment variables. See Running Test Programs: Advanced Options for more details.
Writing a GTest Unit Test
GTest will run tests in parellel. Don't add unit tests that are not threadsafe such as tests that require focus or use specific sockets.
GTest will run without initializing mozilla services. Initialize and tear down any depenencies you have in your test fixtures. Avoid writing integration tests and focus on testing individual units.
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