Testcase - Using FileReadInfo to read external data
User's Guide
193
8 G
ENERALIZING
A
T
ESTCASE
Using data-driven testcases
testcase FindTest (SEARCHINFO Data)
TextEditor.File.New.Pick ()
DocumentWindow.Document.TypeKeys (Data.sText + Data.sPos)
TextEditor.Search.Find.Pick ()
Find.FindWhat.SetText (Data.sPattern)
Find.CaseSensitive.SetState (Data.bCase)
Find.Direction.Select (Data.sDirection)
Find.FindNext.Click ()
Find.Cancel.Click ()
DocumentWindow.Document.VerifySelText ({Data.sExpected})
TextEditor.File.Close.Pick ()
MessageBox.No.Click ()
When the script is run
When you select Run/Run, the main function is called and the FindTest
testcase will be executed once for every instance of Data in lsData (the list of
SEARCHINFO
records). In the script shown above, the testcase will be run
twice. Here is the results file that is produced:
Script findtest.t - Passed
Passed:
2 tests (100%)
Failed:
0 tests (0%)
Totals:
2 tests, 0 errors, 0 warnings
Testcase FindTest ({"Test Case", "<END>", "C", TRUE, "Up", "C"}) - Passed
Testcase FindTest ({"Test Case", "<END>", "Ca", TRUE, "Up", "Ca"}) - Passed
Notice that with data-driven testcases, SilkTest records in the results file the
parameters that are passed in.
Using FileReadInfo to
read external data
In this sample data-driven testcase, the testcase data is stored in a list within
the script itself. It is also possible to store the data externally and read records
into a list using the FileReadValue function. For more information on this
function, see online Help.
Testing an application with invalid data
To thoroughly test an application feature, you need to test the feature with
invalid as well as valid data.
For example, the sample Text Editor application displays a message box if a
user specifies a search string in the Find dialog that doesn't exist in the
document. To account for this, you can create a data-driven testcase, like the
following, that verifies that the message box appears and has the correct
message: