Home > SQL Developer: Unit Testing > Using Lookups to Simplify U...
A lookup is an object that contains, for one or more data types, data values that can be tested. Lookups are mainly used for the following purposes:
Providing lists of values (dropdown lists) for Input fields, as explained in Providing Values for Input Fields.
Automatically creating test implementations based on lookup values, as explained in Automatically Creating Implementations.
To create a lookup:
In the Unit Test navigator, right-click the Lookups node and select Add Category.
Specify the category name (for example, EMP_ID_LOOKUP).
For each data type for which you want to specify lookup values (that is, valid and invalid data values for possible testing), right-click the category name and select Add Datatype, select the data type, and use the + (plus sign) icon to add as many data values as you want.
Note that (null)
is automatically included in the list of values for each data type for each lookup that you create.
For example, for the environment described in Example of Unit Testing (Tutorial), you could create lookups named EMP_ID_LOOKUP and SALES_AMT_LOOKUP. Each would have only one data type: NUMBER. For the NUMBER data for each lookup, use the + (plus sign) icon to add each of the following values on a separate line, and click the Commit Changes icon or press F11 when you are finished entering the set of numbers for each lookup:
For EMP_ID_LOOKUP: -100, 99, 1001, 1002, 1003, 1004, 2000, 9999
For SALES_AMT_LOOKUP: -1000, 0, 1000, 2000, 5000, 6000, 10000, 99999
You can delete and rename lookup categories by using the context (right-click) menu in the Unit Test navigator. You can also delete a data type under a lookup category; however, "deleting" in this case removes any currently specified data values for that type for the lookup category, and it makes the type available for selection in the Unit Testing: Add Data Type dialog box.
When you are specifying Input parameters for a unit test implementation, you can click the Lookup Category control to select a lookup category. When you then click in a cell under Input, you can click the dropdown arrow to select a value from the specified lookup. (You can also enter a value other than one in the list.)
For example, if you created the EMP_ID_LOOKUP lookup category as explained in Using Lookups to Simplify Unit Test Creation, and if you select it as the lookup category when specifying parameters, then the values -100, 99, 1001, 1002, 1003, 1004, 2000, 9999, and (null) will be in the dropdown list for the Input cell for the EMP_ID parameter. (For the SALES_AMT parameter, use the SALES_AMT_LOOKUP category.)
If you know that you want implementations to test certain values for a data type, you can use a lookup category to generate these implementations automatically instead of creating them all manually. To do this, use either the DEFAULT lookup category or a user-created category, specify the values for the desired data type, then specify that lookup category for the Configuration set to use for lookups preference in the Unit Test Parameters preferences.
For example, assume that for NUMBER input parameters, you always want to check for a very high positive number (such as 9999), a very low negative number (such as -9999), 1, -1, and 0 (zero). Follow these steps:
In the Unit Test navigator, expand the Lookups node.
Right-click DEFAULT and select Add Datatype.
In the dialog box, specify NUMBER.
In the Lookups Editor for the NUMBER type, use the + (plus sign) icon to add each of the following as a separate item (new line).
9999 1.0 0 -1.0 -9999
Click the Commit Changes icon or press F11.
Click Tools, then Preferences, then Unit Test Parameters, and ensure that the configuration set to use for lookups is DEFAULT (the lookup category for which you just specified the values for the NUMBER data type).
Create the unit test in the usual way: in the Unit Test navigator, right-click the Tests node and select Create Test.
However, in the Specify Test Name step, select Seed/Create implementations using lookup values (that is, not "Create with single dummy representation").
For Specify Startup and Specify Teardown, specify any desired action.
You cannot specify anything for Specify Parameters or Specify Validations now. An implementation (with a name in the form Test Implementation
n
) will automatically be created for each possible combination of input parameters of type NUMBER. For any validation actions, you must specify them later by editing each generated implementation.
Related Topics