Parameterized tests
Summarize
Summary of Parameterized tests
Parameterized tests in ServiceNow's Automated Test Framework (ATF) enable you to run the same test multiple times using different sets of test data. This approach eliminates the need to duplicate test steps for varying data, increases test reuse by separating test logic from data, and generates individual results for each data set. For example, you can test an incident form by varying subcategory and priority fields using different parameter values.
Show less
Note: The "Run Server Side Script" test step is not supported in parameterized tests.
Key Components
- Parameter: A variable with a unique label and data type that stores test data values. Parameters can be shared across multiple tests or exclusive to a single test. Shared parameters are stored as columns in the Test Run Data Sets table, while exclusive parameters are stored as records in the Parameter Variables table.
- Data Set: Also called test run data sets, these define specific values for each parameter during test execution. You can create data sets manually or import them from files. Each data set corresponds to a record in the Test Run Data Sets table. Tests will fail if no data sets are defined.
Design Considerations
- Parameterized tests support standard ATF features such as reporting, test suites, and data rollback.
- Copying a parameterized test duplicates all parameters, data sets, and test steps.
- If your test includes Custom UI steps, only the first data set is used to retrieve components.
Test Execution and Results
ATF runs a parameterized test once per data set, following the same test steps and order each time. For example, five data sets result in five test runs. Test results display in execution order, with each result record showing parameters and data sets used.
Practical Steps for ServiceNow Customers
- Create a parameterized test: Build tests that utilize variables to hold test data.
- Add parameters to test steps: Insert variables in steps to capture specific data types during execution.
- Add or import data sets: Define or upload test run data to supply parameter values at runtime.
Run a test multiple times with different test data for each run. Create parameters to store test data for each test run.
Parameterized testing offers test designers these benefits.
- Eliminates the need to duplicate test steps just to change test data.
- Increases test reuse by separating test actions from test data.
- Produces a separate test result for each data set.
When the test runs, Automated Test Framework replaces the parameters with data set values. For example, you can create a test of the incident form that uses parameter values for the subcategory and priority fields. You can use one data set to test that the Antivirus category produces a high priority incident, and another data set to test that the Email category produces a low priority incident.
Parameterized test components
Parameterized tests consist of these components.
- Parameter
A parameter is a variable that stores a particular type of test data. Each parameter has a unique label and a data type. For example, you can create a parameter to store the Sys ID of a reference field or the integer value of a choice field. Define parameters during test design.
Parameters can be shared or exclusive. Shared parameters can be used in any parameterized test. Exclusive parameters can only be used with the test for which they were created. Each shared parameter is a column in the Test Run Data Sets [sys_atf_parameter_set] table. Each exclusive parameter is a record in the Parameter Variables [sys_atf_parameter_variable] table.
- Data set
A data set, also known as a test run data set, includes runtime data used when the test runs. You can set a value for every parameter available to the current test. Data sets specify the parameter value during test runs. You can manually create data sets for a test, or import data from a file. Each data set is a record in the Test Run Data Sets [sys_atf_parameter_set] table.
Parameterized tests fail if data sets are not defined.
Design Considerations
Follow these design considerations when creating parameterized tests.
- Parameterized tests support standard Automated Test Framework features, such as reports, test suites, and data rollback. Copying a parameterized test copies all parameters, test run data sets, and test steps.
- If you create a parameterized test that includes Custom UI test steps, the system only uses the first data set to retrieve components.
Parameterized test runs
Automated Test Framework runs each parameterized test once per data set, using the same test steps and execution order. For example, if a parameterized test has five data sets, Automated Test Framework runs the test five times, once for each data set.
Parameterized test results
Parameterized tests display test results by the execution order of the data sets. Open each test result record to view the test details.
The Parameterized Test Result record Description field lists the parameters and data sets used in the test run.