The Google Test unit-testing framework is available in MySQL source trees and distributions as of MySQL 5.6.1. Google Test, like MyTAP, provides a unit-testing framework, but Google Test provides richer functionality, such as:
A rich set of predicates
User-defined predicates and assertions
Automatic test registration
Nice error reporting when a predicate fails (with line number, expected and actual values, and additional comments)
Test fixtures, and setup/teardown logic
Death tests
Disabled tests
Test filtering and shuffling
Google Test runs on many platforms. Some functionality is missing on some platforms (such as death tests and parameterized tests), so those features should not be used.
This section provides notes about using Google Test within the context of MySQL development. For general-purpose information about Google Test, see these resources:
Main Google Test page: http://code.google.com/p/googletest
Primer: http://code.google.com/p/googletest/wiki/GoogleTestPrimer
Advanced guide: http://code.google.com/p/googletest/wiki/GoogleTestAdvancedGuide
Google presentation: http://docs.google.com/present/view?id=dfsbxvm5_0f5s4pvf9
MySQL sources do not include Google Test. To install it so that you can use it, use one of these approaches:
Install Google Test in individual source
trees. If you build with CMake,
use the -DENABLE_DOWNLOADS=1 configuration
option. This causes CMake to download
Google Test and install it in your source tree for you.
Install a single instance of Google Test. This installation method works for both CMake and autotools builds. MySQL requires Google Test 1.5 or higher.
To install from a tarball, download http://googletest.googlecode.com/files/gtest-1.5.0.tar.gz.
To download Google Test from the Subversion repository, see http://code.google.com/p/googletest/source/checkout.
If a Google Test package is available for your operating system, you can install it using the package manager. For example, you might be able to use apt-get for Debian Linux.
When Google Test has been installed, set the
GTEST_PREFIX environment variable
appropriately for your command interpreter. For example, use
this command line for bash:
GTEST_PREFIX=/path/to/your/install; export GTEST_PREFIX
Installing Google Test in individual source trees is the recommended method. The single-instance installation method can be used only if all MySQL builds on a machine take place in the same environment (same operating system, same compiler), for reasons discussed at https://groups.google.com/group/googletestframework/browse_thread/thread/668eff1cebf5309d?pli=1.
At configuration time, CMake or
configure looks for
gtest.h. The build process compiles all
Google Test-based unit tests or ignores them, depending on whether
gtest.h is found.
After the build has completed, run the unit tests using this command:
make test-unit
If you build using CMake, another way to run
the tests is to change location into the
unittest/gunit directory and run the
ctest command. It need not be run with any
options, but you can run it with the --help
option to see what options are available.
For internal MySQL testing, PushBuild has been extended to install
Google Test as a separate “package.” All trees named
mysql-trunk.* are set up to depend on this
package.
The Google Test unit test files are located in the
unittest/gunit directory. You can look at
these files to see how tests are written. Here are some examples:
sql_list-t.cc: A simple test of some list
classes
mdl-t.cc: Some tests of metadata locking
(MDL), including testing of lock acquisition from multiple
threads
mdl_mytap-t.cc: The same tests as
mdl-t.cc, but written for MyTAP, to
illustrate some features of Google Test
Those tests are built for both CMake and autotools builds. For future tests, it is preferable to write CMake targets. MySQL development is moving to CMake, and maintaining library and build dependencies is much easier with CMake than with autotools.
Most MyTAP-based tests are likely easily converted to Google Test. However, there might be low-level tests that absolutely must be run on every platform, and thus require MyTAP.
As currently implemented, the Google Test unit-test programs
produce TAP output rather than the “plain”
alternative. This can be disabled by using the
--disable-tap-output command-line option when
running a test executable.
To see what options are available, run a test executable with the
--help option.

User Comments
Add your own comment.