When you begin planning how to "parameterize" a test, start analyzing the test at the script level. On a script-by-script basis, examine where you might want to replace data with parameters. Good candidates for parameters are any place where a script:
These aren't the only places where you might want to replace hard-coded data with parameters, but they get you off to a good start.
Looking at the acceptance test you created in the last chapter, there are several places where parameters would increase versatility. Perhaps the most obvious candidates are scripts that require a filename, and scripts that work with field data for a name database record.
OpenFile
is the only script that uses the database filename: it's hard-coded to load and verify test.db
. You can change this filename to a parameter and then define the filename when you run the test. This makes this script easier to use in other composed tests, and also gives you ways to adapt Acceptance.jst
for multiple, varied test runs.
As far as record data is concerned, Acceptance.jst
is now hard-coded to create, select, and verify the "Count von Count
" record. This is a somewhat limited test case. You can build other tests with the scripts that make up the acceptance test, but you are still restricted to the "Count von Count
" data. If, instead, you modify the scripts to take the field values as parameters, your scripts will function independent of the data. Re-use potential then increases enormously.
Examining the scripts of the acceptance test, you can see that four scripts use data from the same record:
These four scripts use the same six parameters:
With the addition of the filename for the test database, you'll be editing your tests to use a total of seven parameters.
To change these scripts to use parameters, you'll edit the .java
files to replace the hard-coded data with argument references. At runtime, a script takes any parameters passed to it and places the parameters within the args[]
array. This means that for every script, the first parameter becomes args[0]
, the second args[1]
, the third args[2]
, and so on. So, when you edit EnterFieldData, you'll replace the current field values with args[0]
through args[5]
. Within OpenFile, you'll replace the test.db
string with args[0]
, as well.
Send feedback to
JavaStar-feedback@suntest.com
Copyright © 1998
Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, CA 94303.
All rights reserved.