After creating a number of test cases in Squish, you might find that many of them have some basic structure and functionality in common. When it comes to common functionality the solution is to use shared scripts (see How to Create and Use Shared Data and Shared Scripts). But for common structure the solution is to use a template. Once you have a template, instead of creating each test script from scratch and copy and pasting, you can tell the Squish IDE to create a new test script based on a template and have the skeleton already in place ready for you to customize.
Each new test case template is effectively a copy of an existing test. So to create a new test case template, first create a new "dummy" test case, and then copy or type into the
test.js, etc.) test script exactly—and only—the code that you want in the template. For example, you might create a test case template like this (which happens to use Python, but the same applies in principle to any scripting language):
import os import re import sys # Import functionality needed by more than one test script source(findFile("scripts", "common.py")) def main(): pass
Here we always import some standard library modules and our own custom file (
common.py), that contains functions that we want all our tests to be able to access.
Once we have created the dummy test case with the contents we want to use for the template, we are ready to create the template itself. To do this, invoke the Test Suites view's Test Cases list's context menu and choose the Create Template from Testcase option. This will pop up the Create Test Case Template dialog—simply enter the template's name and click the OK button to create a template that is an exact copy of the currently highlighted test case (i.e., the dummy test case).
Once the test case template has been created it is safe to delete the dummy test case.
Once we have created one or more templates we can use them whenever we want to create a new test case. This is easily done. First click the main window's New toolbar button or press Ctrl+N—either of these will pop up the New dialog. Now choose the "Squish Test Case from Template" item and click the Next button. Now enter a name for the new test case and then click the template you wish to use for it, and finally, click the Finish button. After a moment the new test case will appear in the current test suite, and its
test.js, etc.) file will have exactly the same contents as the template you chose.
Test case templates are stored in a default directory. If you prefer to store them somewhere else—perhaps in a directory that is version controlled, you can easily do so. To change the directory click Preferences and then click the Squish item and then the Test Creation subitem to make the Test Creation pane visible. This pane shows the default template directory—click the Browse button to pop up a directory chooser dialog through which you can set the directory of your choice.
Note: Some older versions of Squish used the
SQUISH_TESTCASE_TEMPLATES_DIR environment variable to specify where test templates are stored. This environment variable is no longer supported, so if you have been using it you must change the directory in the Squish IDE as described above.
© 2023 The Qt Company Ltd.
Documentation contributions included herein are the copyrights of
their respective owners.
The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation.
Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.