MySQL 8.0.40
Source Code Documentation
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.

  1. Change location to the test directory mysql-version/mysql-test:

    shell> cd mysql-version/mysql-test

    mysql-version represents the root directory of your source tree.

  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.

  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:

    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:

    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.