2.6. Modifying and Creating Tests

To fix the test, you need to change the arguments to the test. Select Edit Test from the Edit menu. QMTest will display a form that allows you to change the arguments to the test.

Change the second argument, labeled "Python Expression," to x + x == 4. Then click on the OK button at the bottom of the page to save your changes. Choose This Test from the Run menu and observe that the test now passes.

Creating a new test works in a similar way. Choose Directory under the View menu to return to the main QMTest page. Then, select New Test from the File menu to create a new test. QMTest displays a form that contains two fields: the test name, and the test class. The test name identifies the test; the test class indicates what kind of test will be created.

Test names must be composed entirely of lowercase letters, numbers, the "_" character, and the "." character. You can think of test names like file names. The "." character takes the place of "/" on UNIX or "\" on Windows; it allows you to place a test in a particular directory. For example, the test name a.b.c names a test named c in the directory a.b. The directory a.b is a subdirectory of the directory a. By organizing your tests in directories, you will make it easier to keep track of your tests. In addition, QMTest can automatically run all the tests in a particular directory, so by using directories you will make it easy to run a group of related tests at once.

Enter command.test1 for the test name. This will create a new test named test1 in the command directory. Choose command.ShellCommandTest as the test class. This kind of test runs a command and compares its actual output against the expected output. If they match, the test passes. This test class is useful for testing many programs. Click on the Next button to continue.

Now, QMTest will present you with a form that looks just like the form you used to edit exec1, except that the arguments are different. The arguments are different because you're creating a different kind of test. Enter echo test in the Command field. This command will produce an output (the word test), so find the Standard Output box and enter test in this box. When you are done, click the OK button at the bottom of the form.

Now you can select This Test from the Run menu to run the test.

When you're done experimenting with QMTest, choose Exit from the File menu.