Storage engines and plugins can have unit tests to test their
components. The top-level Makefile
target
test-unit
run all unit tests: It scans the
storage engine and plugin directories, the engines' and plugins'
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
that 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/
or
engine_name
plugin/
),
or one of its subdirectories. A reasonable convention is to create a
plugin_name
unittest
subdirectory under the storage engine
or plugin directory and create unit test files in
unittest
.