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發(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能力的操作或邏輯劈愚。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市闻妓,隨后出現(xiàn)的幾起案子菌羽,更是在濱河造成了極大的恐慌,老刑警劉巖由缆,帶你破解...
    沈念sama閱讀 217,277評(píng)論 6 503
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件注祖,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡均唉,警方通過(guò)查閱死者的電腦和手機(jī)是晨,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,689評(píng)論 3 393
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)舔箭,“玉大人罩缴,你說(shuō)我怎么就攤上這事蚊逢。” “怎么了箫章?”我有些...
    開封第一講書人閱讀 163,624評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵烙荷,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我檬寂,道長(zhǎng)终抽,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,356評(píng)論 1 293
  • 正文 為了忘掉前任桶至,我火速辦了婚禮昼伴,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘镣屹。我一直安慰自己圃郊,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,402評(píng)論 6 392
  • 文/花漫 我一把揭開白布女蜈。 她就那樣靜靜地躺著描沟,像睡著了一般。 火紅的嫁衣襯著肌膚如雪鞭光。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,292評(píng)論 1 301
  • 那天泞遗,我揣著相機(jī)與錄音惰许,去河邊找鬼。 笑死史辙,一個(gè)胖子當(dāng)著我的面吹牛汹买,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播聊倔,決...
    沈念sama閱讀 40,135評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼晦毙,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了耙蔑?” 一聲冷哼從身側(cè)響起见妒,我...
    開封第一講書人閱讀 38,992評(píng)論 0 275
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎甸陌,沒(méi)想到半個(gè)月后须揣,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,429評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡钱豁,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,636評(píng)論 3 334
  • 正文 我和宋清朗相戀三年耻卡,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片牲尺。...
    茶點(diǎn)故事閱讀 39,785評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡卵酪,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情溃卡,我是刑警寧澤溢豆,帶...
    沈念sama閱讀 35,492評(píng)論 5 345
  • 正文 年R本政府宣布,位于F島的核電站塑煎,受9級(jí)特大地震影響沫换,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜最铁,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,092評(píng)論 3 328
  • 文/蒙蒙 一讯赏、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧冷尉,春花似錦漱挎、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,723評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至雾棺,卻和暖如春膊夹,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背捌浩。 一陣腳步聲響...
    開封第一講書人閱讀 32,858評(píng)論 1 269
  • 我被黑心中介騙來(lái)泰國(guó)打工放刨, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人尸饺。 一個(gè)月前我還...
    沈念sama閱讀 47,891評(píng)論 2 370
  • 正文 我出身青樓进统,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親浪听。 傳聞我的和親對(duì)象是個(gè)殘疾皇子螟碎,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,713評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容

  • 1****、概述 在我們給MySQL打了patch后迹栓,不僅需要測(cè)試新增的功能掉分,同時(shí)更重要的問(wèn)題是,需要對(duì)原有的功能...
    祁小彬閱讀 1,972評(píng)論 1 2
  • 在很久很久以前褥民,測(cè)試工程師面試是這樣開始的:“給你個(gè)杯子,你打算怎么測(cè)試洗搂?”“我會(huì)如此… 這樣… 然后… 接下來(lái)…...
    碼同學(xué)軟件測(cè)試閱讀 52評(píng)論 0 0
  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見(jiàn)模式的工具(例如配置管理消返,服務(wù)發(fā)現(xiàn)载弄,斷路器,智...
    卡卡羅2017閱讀 134,654評(píng)論 18 139
  • 洞見(jiàn)SELENIUM自動(dòng)化測(cè)試 寫在最前面:目前自動(dòng)化測(cè)試并不屬于新鮮的事物撵颊,或者說(shuō)自動(dòng)化測(cè)試的各種方法論已經(jīng)層出...
    厲鉚兄閱讀 6,728評(píng)論 3 47
  • 1.軟件測(cè)試級(jí)別宇攻? 單元測(cè)試:?jiǎn)卧獪y(cè)試是對(duì)軟件組成單元進(jìn)行測(cè)試。其目的是檢驗(yàn)軟件基本組成單位的正確性倡勇。測(cè)試的對(duì)象是...
    聽聞白依閱讀 1,413評(píng)論 0 9