Databases 8 min read

Installing and Using the MySQL Test Framework for Unit, Regression, and Consistency Testing

This guide explains what the MySQL Test framework is, how to set up the required environment on Ubuntu, install dependencies and MySQL source, configure and compile the test suite, and demonstrates creating and running a simple test case with detailed command‑line examples.

Aikesheng Open Source Community
Aikesheng Open Source Community
Aikesheng Open Source Community
Installing and Using the MySQL Test Framework for Unit, Regression, and Consistency Testing

What is MySQL Test? MySQL Test is an all‑in‑one testing framework integrated into MySQL distribution, providing tools for unit, regression, and consistency testing of MySQL services. It consists of a set of test cases and two executables: a Perl script ( mysql-test-run.pl ) that controls the test flow, and a C++ binary ( mysqltest ) that parses and runs the test cases.

Installation Environment

OS: Ubuntu 18.04.1 LTS

1. Download MySQL source package

wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.26.tar.gz

2. Install build dependencies

apt install make cmake gcc g++ perl \
    bison libaio-dev libncurses5 \
    libncurses5-dev libnuma-dev

If the download is slow, replace the default /etc/apt/sources.list with a domestic mirror, e.g.:

deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
... (other repository lines) ...

3. Install Boost 1.59 (required version)

wget https://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
./bootstrap.sh
./b2 install

4. Configure, compile, and install MySQL

cmake . -DBUILD_CONFIG=mysql_release -DCPACK_MONOLITHIC_INSTALL=ON -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQLX_TCP_PORT=33060 -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DMYSQL_TCP_PORT=3306 -DMYSQLX_UNIX_ADDR=/usr/local/mysql/mysqlx.sock -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/usr/local/mysql/etc -DENABLE_DOWNLOADS=ON -DWITH_BOOST=system
make -j4
make install

After compilation, the MySQL installation directory contains a structure similar to:

drwxr-xr-x  2 root root   4096 collections/
drwxr-xr-x  4 root root   4096 extra/
drwxr-xr-x  2 root root  40960 include/
drwxr-xr-x  4 root root   4096 lib/
... (other directories and files) ...

Test Example

We illustrate the framework with a simple test case.

1. Create a test case

In the mysql-test/t directory, create a file named action_1st.test with the following content:

--disable_warnings
DROP TABLE IF EXISTS t1;
SET @@sql_mode='NO_ENGINE_SUBSTITUTION';
--enable_warnings
SET SQL_WARNINGS=1;
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1);
INSERT INTO t1 VALUES (2);
DROP TABLE t1;

In the mysql-test/r directory, create the expected result file action_1st.result :

DROP TABLE IF EXISTS t1;
SET @@sql_mode='NO_ENGINE_SUBSTITUTION';
SET SQL_WARNINGS=1;
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1);
INSERT INTO t1 VALUES (2);
DROP TABLE t1;

2. Run the test and view the output

./mtr action_1st.test

The command produces a detailed log, checks features, creates a temporary var directory, installs the system database, and finally runs the test, reporting:

[100%] main.action_1st                          [ pass ]     12
Completed: All 1 tests were successful.

The framework automatically compares the actual output with the expected result file; if they differ, the test fails.

testinglinuxMySQLTest FrameworkcmakeBoostPerlUbuntu
Aikesheng Open Source Community
Written by

Aikesheng Open Source Community

The Aikesheng Open Source Community provides stable, enterprise‑grade MySQL open‑source tools and services, releases a premium open‑source component each year (1024), and continuously operates and maintains them.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.