mtr Writing a Test Case - Quick Start

The basic principle of test case evaluation is that output resulting from running a test case is compared to the expected result.
测试用例评估的基本原则是将运行测试用例的输出与预期结果进行比较。

This is just a diff comparison between the output and an expected-result file that the test writer provides. This simplistic method of comparison does not by itself provide any way to handle variation in the output that may occur when a test is run at different times. However, the test language provides commands for postprocessing result output before the comparison occurs. This enables you to manage certain forms of expected variation.
这只是输出和测试编写者提供的预期结果文件之间的差异比较。这种简单的比较方法本身并没有提供任何方法来处理在不同时间运行测试时可能出现的输出变化。但是,测试语言在进行比较之前为后处理结果输出提供了命令。这使您能够管理特定形式的预期变化。

Use the following procedure to write a new test case. In the examples, test_name represents the name of the test case. It is assumed here that you'll be using a development source tree, so that when you create a new test case, you can commit the files associated with it to the source repository for others to use.
使用以下过程来编写一个新的测试用例。在示例中,test_name表示测试用例的名称。这里假设您将使用一个开发源代码树,这样当您创建一个新的测试用例时,您就可以将与它相关联的文件提交到源存储库以供其他人使用。

  • 1 Change location to the test directory mysql-version/mysql-test:
    更改位置到测试目录mysql-version/mysql-test:

    shell> cd mysql-version/mysql-test
    

    mysql-version represents the root directory of your source tree.
    Mysql-version表示源树的根目录。

  • 2 Create the test case in a file t/test_name.test. You can do this with any text editor. For details of the language used for writing mysqltest test cases, see mysqltest Language Reference.
    在文件t/test_name.test中创建测试用例。任何文本编辑器都可以做到这一点。关于编写mysqltest测试用例所用语言的详细信息,请参见mysqltest语言参考。

  • 3 Create an empty result file:
    创建一个空的结果文件:

    shell> touch r/test_name.result
    
  • 4 Run the test:

    shell> ./mysql-test-run.pl test_name
    
  • 5 Assuming that the test case produces output, it should fail because the output does not match the result file (which is empty at this point). The failure results in creation of a reject file named mysql-test/var/log/test_name.reject. Examine this file. If the reject file appears to contain the output that you expect the test case to produce, copy its content to the result file:
    假设测试用例产生输出,它应该会失败,因为输出与结果文件不匹配(此时是空的)。创建拒绝文件,文件名为“mysql-test/var/log/test_name.reject”。检查这个文件。如果被拒绝的文件包含您期望测试用例产生的输出,那么将其内容复制到结果文件中:

    shell> cp mysql-test/var/log/test_name.reject r/test_name.result
    

    Another way to create the result file is by invoking mysql-test-run.pl with the --record option to record the test output in the result file:
    创建结果文件的另一种方法是使用——record选项调用mysql-test-run.pl,在结果文件中记录测试输出:

    shell> ./mysql-test-run.pl --record test_name
    
  • 6 Run the test again. This time it should succeed:
    重新执行测试。这一次它应该会成功:

    shell> ./mysql-test-run.pl test_name
    

    You can also run the newly created test case as part of the entire suite:
    你也可以运行新创建的测试用例作为整个套件的一部分:

    shell> ./mysql-test-run.pl
    

It is also possible to invoke the mysqltest program directly. If the test case file refers to environment variables, you will need to define those variables in your environment first. For more information about the mysqltest program, see mysqltest — Program to Run Test Cases.
也可以直接调用mysqltest程序。如果测试用例文件引用了环境变量,您将需要首先在您的环境中定义这些变量。有关mysqltest程序的更多信息,请参见mysqltest -运行测试用例的程序。

你可能感兴趣的:(mtr Writing a Test Case - Quick Start)