Introduction to the MySQL Test Framework
MySQL distributions include a test suite: a set of test cases and programs for running them.
MySQL發(fā)行版包括一個(gè)測(cè)試套件:一組用于運(yùn)行它們的測(cè)試用例和程序退个。
(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.
(如果您發(fā)現(xiàn)該測(cè)試套件不包含在您的發(fā)行版中孩灯,請(qǐng)查找名稱中帶有-test的類似發(fā)行版并安裝它。)這些工具構(gòu)成了MySQL測(cè)試框架丑婿,提供了一種方法來(lái)驗(yàn)證MySQL服務(wù)器及其客戶端程序是否按照預(yù)期運(yùn)行搜骡。測(cè)試用例主要由SQL語(yǔ)句組成疹娶,但也可以使用控制如何運(yùn)行測(cè)試和驗(yàn)證結(jié)果的測(cè)試語(yǔ)言結(jié)構(gòu)书斜。發(fā)行版還提供了運(yùn)行單元測(cè)試和創(chuàng)建新單元測(cè)試的工具。
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測(cè)試框架的組成部分混弥,測(cè)試程序如何工作趴乡,以及用于編寫測(cè)試用例的語(yǔ)言。它還提供了開發(fā)測(cè)試用例和執(zhí)行它們的教程蝗拿。
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.
運(yùn)行測(cè)試套件的應(yīng)用程序名為mysql-test-run.pl晾捏。它的位置是MySQL -test目錄,它在源碼和二進(jìn)制MySQL服務(wù)器發(fā)行版中都有哀托。
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以外的平臺(tái)上惦辛,也可以通過(guò)同一個(gè)目錄中的簡(jiǎn)短名稱mtr使用mysql-test-run.pl,可以作為符號(hào)鏈接或副本使用仓手。
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 應(yīng)用程序啟動(dòng)MySQL服務(wù)器胖齐,當(dāng)特定的測(cè)試用例需要不同的啟動(dòng)參數(shù)時(shí),根據(jù)需要重新啟動(dòng)它們嗽冒,并顯示測(cè)試結(jié)果呀伙。對(duì)于每個(gè)測(cè)試用例,mysql-test-run.pl調(diào)用mysqltest程序(也稱為“測(cè)試引擎”)來(lái)讀取測(cè)試用例文件,解釋測(cè)試語(yǔ)言構(gòu)造,并將SQL語(yǔ)句發(fā)送到服務(wù)器惕蹄。
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.
每個(gè)測(cè)試用例的輸入存儲(chǔ)在一個(gè)文件中炉菲,而運(yùn)行測(cè)試的預(yù)期結(jié)果存儲(chǔ)在另一個(gè)文件中。運(yùn)行測(cè)試后舶替,將實(shí)際結(jié)果與預(yù)期結(jié)果進(jìn)行比較鸡典。
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.
對(duì)于MySQL源碼芳悲,MySQL -test-run.pl位于MySQL -test目錄下氛堕,而mysqltest位于客戶端目錄下馏臭。mysql-test和client目錄位于發(fā)行版的根目錄中。
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.
對(duì)于MySQL二進(jìn)制版本讼稚,MySQL -test-run.pl位于MySQL -test目錄下位喂,mysqltest與其他客戶端程序(如MySQL或mysqladmin)位于同一個(gè)目錄下。mysql-test和其他目錄的位置取決于用于分發(fā)格式的布局乱灵。
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目錄中,測(cè)試用例輸入文件和結(jié)果文件分別存儲(chǔ)在t和r目錄中七冲。輸入文件和結(jié)果文件具有相同的基本名痛倚,即測(cè)試名稱,但擴(kuò)展名分別為.test和.result澜躺。例如蝉稳,對(duì)于一個(gè)名為“decimal”的測(cè)試,輸入和結(jié)果文件是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.
每個(gè)測(cè)試文件被稱為一個(gè)測(cè)試用例耘戚,但是通常由一系列相關(guān)的測(cè)試組成。測(cè)試用例中單個(gè)語(yǔ)句的意外失敗會(huì)導(dǎo)致測(cè)試用例失敗操漠。
There are several ways a test case can fail:
測(cè)試用例可能會(huì)以幾種方式失敗:
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測(cè)試引擎檢查執(zhí)行測(cè)試輸入中的每個(gè)SQL語(yǔ)句的結(jié)果代碼收津。如果失敗是意外的,測(cè)試用例就會(huì)失敗浊伙。
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).
如果預(yù)期出現(xiàn)錯(cuò)誤但沒(méi)有發(fā)生錯(cuò)誤撞秋,測(cè)試用例可能會(huì)失敗(例如,如果SQL語(yǔ)句在應(yīng)該失敗的情況下成功了)嚣鄙。
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.
測(cè)試用例可能會(huì)因?yàn)楫a(chǎn)生不正確的輸出而失敗吻贿。當(dāng)測(cè)試運(yùn)行時(shí),它會(huì)產(chǎn)生輸出(SELECT哑子、SHOW和其他語(yǔ)句的結(jié)果)舅列。該輸出將與mysql-test/r目錄(后綴為.result的文件)中的預(yù)期結(jié)果進(jìn)行比較。如果預(yù)期的和實(shí)際的結(jié)果不同卧蜓,測(cè)試用例就失敗了帐要。實(shí)際的測(cè)試結(jié)果被寫入mysql-test/var/log目錄下的一個(gè)文件中,后綴為.reject烦却,并且.result和.reject文件之間的差異會(huì)被顯示出來(lái)以供評(píng)估宠叼。
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服務(wù)器在測(cè)試過(guò)程中意外死亡,測(cè)試用例將失敗。如果發(fā)生這種情況冒冬,mysqltest測(cè)試客戶端通常也會(huì)報(bào)告一個(gè)由于失去連接而導(dǎo)致的失敗伸蚯。
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.
最后,如果測(cè)試期間由MySQL服務(wù)器編寫的錯(cuò)誤日志包含未過(guò)濾(抑制)的警告或錯(cuò)誤简烤,則測(cè)試用例將失敗剂邮。有關(guān)抑制警告的更多信息,請(qǐng)參閱抑制錯(cuò)誤和警告横侦。
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.
這種檢查測(cè)試結(jié)果的方法對(duì)如何編寫測(cè)試用例施加了一些限制挥萌。例如,結(jié)果不能包含隨運(yùn)行而變化的信息枉侧,例如當(dāng)前時(shí)間引瀑。但是,如果變化的信息對(duì)測(cè)試評(píng)估不重要榨馁,那么有一些方法可以指示測(cè)試引擎將輸出中的這些字段替換為固定值憨栽。
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.
因?yàn)闇y(cè)試用例主要由文本文件中的SQL語(yǔ)句組成,所以對(duì)用C翼虫、Java或其他語(yǔ)言編寫的測(cè)試用例沒(méi)有直接的支持屑柔。這樣的測(cè)試不在這個(gè)測(cè)試框架的范圍內(nèi)。但是框架支持執(zhí)行您自己的腳本并使用您自己的數(shù)據(jù)初始化它們珍剑。此外掸宛,測(cè)試用例可以執(zhí)行外部程序,因此在某些方面招拙,測(cè)試框架可以擴(kuò)展為測(cè)試SQL語(yǔ)句以外的用途唧瘾。最后,可以在測(cè)試中嵌入一小段Perl代碼别凤。這有時(shí)可以用于執(zhí)行超出測(cè)試語(yǔ)言或SQL能力的操作或邏輯劈愚。