mtr Introduction to the MySQL Test Framework

Introduction to the MySQL Test Framework

MySQL distributions include a test suite: a set of test cases and programs for running them.
MySQL发行版包括一个测试套件:一组用于运行它们的测试用例和程序。

(If you find that the test suite is not included in your distribution, look for a similar distribution with -test in the name and install that as well.) These tools constitute the MySQL test framework that provides a means for verifying that MySQL Server and its client programs operate according to expectations. The test cases consist mostly of SQL statements, but can also use test language constructs that control how to run tests and verify their results. Distributions also provide facilities for running unit tests and creating new unit tests.
(如果您发现该测试套件不包含在您的发行版中,请查找名称中带有-test的类似发行版并安装它。)这些工具构成了MySQL测试框架,提供了一种方法来验证MySQL服务器及其客户端程序是否按照预期运行。测试用例主要由SQL语句组成,但也可以使用控制如何运行测试和验证结果的测试语言结构。发行版还提供了运行单元测试和创建新单元测试的工具。

This document describes the components of the MySQL test framework, how the test programs work, and the language used for writing test cases. It also provides a tutorial for developing test cases and executing them.
本文档描述了MySQL测试框架的组成部分,测试程序如何工作,以及用于编写测试用例的语言。它还提供了开发测试用例和执行它们的教程。

The application that runs the test suite is named mysql-test-run.pl. Its location is the mysql-test directory, which is present both in source and binary MySQL Server distributions.
运行测试套件的应用程序名为mysql-test-run.pl。它的位置是MySQL -test目录,它在源码和二进制MySQL服务器发行版中都有。

On platforms other than Windows, mysql-test-run.pl is also available through the shortened name mtr in the same directory, as either a symbolic link or a copy.
在Windows以外的平台上,也可以通过同一个目录中的简短名称mtr使用mysql-test-run.pl,可以作为符号链接或副本使用。

The mysql-test-run.pl application starts MySQL servers, restarts them as necessary when a specific test case needs different start arguments, and presents the test result. For each test case, mysql-test-run.pl invokes the mysqltest program (also referred to as the “test engine”) to read the test case file, intepret the test language constructs, and send SQL statements to the server.
mysql-test-run.pl 应用程序启动MySQL服务器,当特定的测试用例需要不同的启动参数时,根据需要重新启动它们,并显示测试结果。对于每个测试用例,mysql-test-run.pl调用mysqltest程序(也称为“测试引擎”)来读取测试用例文件,解释测试语言构造,并将SQL语句发送到服务器。

Input for each test case is stored in a file, and the expected result from running the test is stored in another file. The actual result is compared to the expected result after running the test.
每个测试用例的输入存储在一个文件中,而运行测试的预期结果存储在另一个文件中。运行测试后,将实际结果与预期结果进行比较。

For a MySQL source distribution, mysql-test-run.pl is located in the mysql-test directory, and mysqltest is located in the client directory. The mysql-test and client directories are located in the root directory of the distribution.
对于MySQL源码,MySQL -test-run.pl位于MySQL -test目录下,而mysqltest位于客户端目录下。mysql-test和client目录位于发行版的根目录中。

For a MySQL binary distribution, mysql-test-run.pl is located in the mysql-test directory, and mysqltest is located in the same directory where other client programs such as mysql or mysqladmin are installed. The locations of the mysql-test and other directories depend on the layout used for the distribution format.
对于MySQL二进制版本,MySQL -test-run.pl位于MySQL -test目录下,mysqltest与其他客户端程序(如MySQL或mysqladmin)位于同一个目录下。mysql-test和其他目录的位置取决于用于分发格式的布局。

Within the mysql-test directory, test case input files and result files are stored in the t and r directories, respectively. The input and result files have the same basename, which is the test name, but have extensions of .test and .result, respectively. For example, for a test named “decimal”, the input and result files are mysql-test/t/decimal.test and mysql-test/r/decimal.result.
在mysql-test目录中,测试用例输入文件和结果文件分别存储在t和r目录中。输入文件和结果文件具有相同的基本名,即测试名称,但扩展名分别为.test和.result。例如,对于一个名为“decimal”的测试,输入和结果文件是mysql-test/t/decimal.test 和mysql-test / r / decimal.result。

Each test file is referred to as one test case, but usually consists of a sequence of related tests. An unexpected failure of a single statement in a test case makes the test case fail.
每个测试文件被称为一个测试用例,但是通常由一系列相关的测试组成。测试用例中单个语句的意外失败会导致测试用例失败。

There are several ways a test case can fail:
测试用例可能会以几种方式失败:

The mysqltest test engine checks the result codes from executing each SQL statement in the test input. If the failure is unexpected, the test case fails.
mysqltest测试引擎检查执行测试输入中的每个SQL语句的结果代码。如果失败是意外的,测试用例就会失败。

A test case can fail if an error was expected but did not occur (for example, if an SQL statement succeeded when it should have failed).
如果预期出现错误但没有发生错误,测试用例可能会失败(例如,如果SQL语句在应该失败的情况下成功了)。

The test case can fail by producing incorrect output. As a test runs, it produces output (the results from SELECT, SHOW, and other statements). This output is compared to the expected result found in the mysql-test/r directory (in a file with a .result suffix). If the expected and actual results differ, the test case fails. The actual test result is written to a file in the mysql-test/var/log directory with a .reject suffix, and the difference between the .result and .reject files is presented for evaluation.
测试用例可能会因为产生不正确的输出而失败。当测试运行时,它会产生输出(SELECT、SHOW和其他语句的结果)。该输出将与mysql-test/r目录(后缀为.result的文件)中的预期结果进行比较。如果预期的和实际的结果不同,测试用例就失败了。实际的测试结果被写入mysql-test/var/log目录下的一个文件中,后缀为.reject,并且.result和.reject文件之间的差异会被显示出来以供评估。

A test case will fail if the MySQL server dies unexpectedly during the test. If this happens, the mysqltest test client will usually also report a failure due to loosing the connection.
如果MySQL服务器在测试过程中意外死亡,测试用例将失败。如果发生这种情况,mysqltest测试客户端通常也会报告一个由于失去连接而导致的失败。

Finally, the test case will fail if the error log written by the MySQL server during the test includes warnings or errors which are not filtered (suppressed). See Suppressing Errors and Warning for more about suppressing warnings.
最后,如果测试期间由MySQL服务器编写的错误日志包含未过滤(抑制)的警告或错误,则测试用例将失败。有关抑制警告的更多信息,请参阅抑制错误和警告。
This method of checking test results puts some restrictions on how test cases can be written. For example, the result cannot contain information that varies from run to run, such as the current time. However, if the information that varies is unimportant for test evaluation, there are ways to instruct the test engine to replace those fields in the output with fixed values.
这种检查测试结果的方法对如何编写测试用例施加了一些限制。例如,结果不能包含随运行而变化的信息,例如当前时间。但是,如果变化的信息对测试评估不重要,那么有一些方法可以指示测试引擎将输出中的这些字段替换为固定值。

Because the test cases consist mostly of SQL statements in a text file, there is no direct support for test cases that are written in C, Java, or other languages. Such tests are not within the scope of this test framework. But the framework does support executing your own scripts and initiating them with your own data. Also, a test case can execute an external program, so in some respects the test framework can be extended for uses other than testing SQL statements. Finally, it is possible to embed small pieces of Perl code within the test. This can sometimes be used to perform actions or execute logic which is beyond the capabilities of the test language or SQL.
因为测试用例主要由文本文件中的SQL语句组成,所以对用C、Java或其他语言编写的测试用例没有直接的支持。这样的测试不在这个测试框架的范围内。但是框架支持执行您自己的脚本并使用您自己的数据初始化它们。此外,测试用例可以执行外部程序,因此在某些方面,测试框架可以扩展为测试SQL语句以外的用途。最后,可以在测试中嵌入一小段Perl代码。这有时可以用于执行超出测试语言或SQL能力的操作或逻辑。

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 218,036评论 6 506
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 93,046评论 3 395
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 164,411评论 0 354
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,622评论 1 293
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,661评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,521评论 1 304
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,288评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,200评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,644评论 1 314
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,837评论 3 336
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,953评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,673评论 5 346
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,281评论 3 329
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,889评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,011评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,119评论 3 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,901评论 2 355

推荐阅读更多精彩内容

  • 1****、概述 在我们給MySQL打了patch后,不仅需要测试新增的功能,同时更重要的问题是,需要对原有的功能...
    祁小彬阅读 1,977评论 1 2
  • 在很久很久以前,测试工程师面试是这样开始的:“给你个杯子,你打算怎么测试?”“我会如此… 这样… 然后… 接下来…...
    码同学软件测试阅读 52评论 0 0
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,657评论 18 139
  • 洞见SELENIUM自动化测试 写在最前面:目前自动化测试并不属于新鲜的事物,或者说自动化测试的各种方法论已经层出...
    厲铆兄阅读 6,728评论 3 47
  • 1.软件测试级别? 单元测试:单元测试是对软件组成单元进行测试。其目的是检验软件基本组成单位的正确性。测试的对象是...
    听闻白依阅读 1,416评论 0 9