Documentation Home
The MySQL Test Framework, Version 1.0
Download this Manual
PDF (US Ltr) - 443.9Kb
PDF (A4) - 445.6Kb
EPUB - 101.9Kb


The MySQL Test Framework, Version 1.0  /  Creating and Executing Unit Tests

Chapter 7 Creating and Executing Unit Tests

As of MySQL 5.1, storage engines and plugins can have unit tests to test their components. The top-level Makefile target test-unit runs all unit tests: It scans the storage engine and plugin directories, recursively, and executes all executable files with a name that ends with -t.

The unit-testing facility is based on the Test Anything Protocol (TAP) which is mainly used when developing Perl and PHP modules. To write unit tests for C/C++ code, MySQL has developed a library for generating TAP output from C/C++ files. Each unit test is written as a separate source file that is compiled to produce an executable. For the unit test to be recognized as a unit test, the executable file has to be of the format mytext-t. For example, you can create a source file named mytest-t.c the compiles to produce an executable mytest-t. The executable will be found and run when you execute make test or make test-unit in the distribution top-level directory.

Example unit tests can be found in the unittest/examples directory of a MySQL source distribution. The code for the MyTAP protocol is located in the unittest/mytap directory.

Each unit test file should be stored in a storage engine or plugin directory (storage/engine_name or plugin/plugin_name), or one of its subdirectories. A reasonable convention is to create a unittest subdirectory under the storage engine or plugin directory and create unit test files in unittest.


Download this Manual
PDF (US Ltr) - 443.9Kb
PDF (A4) - 445.6Kb
EPUB - 101.9Kb