background image
<< Testcase - Passing data to a testcase | Testcase - Using FileReadInfo to read external data >>
Testcase - Using a main function in the script
<< Testcase - Passing data to a testcase | Testcase - Using FileReadInfo to read external data >>
192
User's Guide
8 G
ENERALIZING
A
T
ESTCASE
Using data-driven testcases
·
If you are using QA Organizer, you do not pass data to a testcase from
the script's main function. Instead, you embed the data in the testplan and
QA Organizer passes the data when you run the testplan. Therefore,
QA Organizer users should skip this section and instead follow the
instructions in "Adding Data to a Testplan" on page 221.
Using a main function
in the script
Although most of the script files you create contain only testcases, in some
instances, you need to add a function named main to your script. You can use
the main function to pass data to testcases as well as control the order in
which the testcases in the script are executed.
When you run a script file using Run/Run:
·
If the script file contains a main function, the main function is executed,
then execution stops. Only testcases and functions called by main will be
executed, in the order in which they are specified in main.
·
If the script does not contain a main function, the testcases are executed
from top to bottom.
The following template shows the structure of a script that contains a main
function that passes data to a data-driven testcase:
main ()
// 1. Declare a variable to hold current record
// 2. Store all data for testcase in a list of records
// 3. Call the testcase once for each record in the list
Example of using main
Using this structure, the following example shows how to create a script that
defines data records and then calls the sample testcase once for each record in
the list:
type SEARCHINFO is record
STRING
sText
// Text to type in document window
STRING
sPos
// Starting position of search
STRING
sPattern
// String to look for
BOOLEAN bCase
// Case-sensitive or not
STRING
sDirection // Direction of search
STRING
sExpected
// The expected match
main ()
SEARCHINFO Data
list of SEARCHINFO lsData = {...}
{"Test Case", "<END>", "C", TRUE, "Up", "C"}
{"Test Case", "<END>", "Ca", TRUE, "Up", "Ca"}
// additional data records can be added here
for each Data in lsData
FindTest (Data)