Parameterized tests
Summarize
Summary of Parameterized tests
Parameterized tests in ServiceNow’s Automated Test Framework (ATF) allow you to run the same test multiple times with different sets of data. By defining variables called parameters, you can separate test logic from test data, enhancing test reuse and efficiency. This approach eliminates the need to duplicate test steps for different inputs and generates individual test results for each data set.
Show less
During a test run, ATF replaces parameters with specified data values. For instance, you can test the incident form by varying the subcategory and priority fields across different data sets to validate multiple scenarios without rewriting the test.
Important: The “Run Server Side Script” test step is not supported in parameterized tests.
Key Features
- Parameters: Variables that hold test data, each with a unique label and data type. Parameters can be shared across tests or exclusive to a single test, enabling flexible data management. Shared parameters correspond to columns in the Test Run Data Sets table, while exclusive parameters are stored in the Parameter Variables table.
- Data Sets: Collections of runtime values assigned to parameters for each test run. You can create data sets manually or import them from files. Each data set represents a distinct test execution scenario. Parameterized tests require defined data sets to execute successfully.
- Test Runs: ATF executes the test once per data set, maintaining consistent test steps and order. For example, a test with five data sets runs five times, producing separate results for each.
- Results: Test outcomes are organized by the execution order of data sets. Detailed results include parameter names and data values used, accessible in individual test result records.
Design Considerations
- Parameterized tests integrate with standard ATF features such as reports, test suites, and data rollback.
- Copying a parameterized test duplicates all associated parameters, data sets, and test steps, preserving test integrity.
- When using Custom UI test steps within parameterized tests, only the first data set is utilized for component retrieval.
Practical Steps for ServiceNow Customers
- Create a parameterized test: Build tests that use variables to hold diverse test data instead of hardcoding values.
- Add parameters to test steps: Define variables within test steps to capture different data types as the test runs.
- Add or import parameterized data sets: Specify or import multiple sets of data values to run the test against various scenarios.
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.