Data-driven testing

Learn how to run the same test with different data

Data-driven testing lets you define parameters in your tests and use them in any step. You can define multiple ordered data sets and have the test run against each set separately using the Testim CLI.

📘

When using data sets, previous data will not be automatically removed from test until explicitly removed.

Popular use cases for Data Driven Testing

  • Run a signup test with different data - when you want to test your signup page with different user name and password, you can use Test Data and Conditions to build one test in Testim that will run several times with different usernames and passwords (negative or positive)
  • Read\inject data from a database - when you want to inject data into a database and then pass the data that was generated by the test. To generate the data you can use Testim CLI hooks and after the injection of the data was successfully completed, you can pass the data to your test.

Adding test data to your tests

Test data can be added to a test in three ways:

  • Through the visual editor (UI) - test data is added through the Test Data property in the Setup step. A Data Set is defined in JavaScript and multiple ordered Data Sets are defined by a JS Array literal of objects. See Configuring a Data-driven Test From The Visual Editor.

  • Through the Config file - the configuration file is a common JS file containing all the required parameters to run your tests, while executing Configuration File Hooks. Through one of these hooks (e.g., beforeSuite), it is possible to add test data to the entire execution or to specified tests. This dataset can override the dataset that was defined in the visual editor. The test can be run using the CLI, while adding a flag to use the config file in this run. The Config file option offers extensive versatility and granular control over the scope in which the data is used:

    • Execution level - placing the data parameters after the return section within the configuration hooks, will run the same data across all the tests included in the execution.

    • Test level - inside the return section, it is possible to add an overrideTestData object, which allows you to add the data to specified tests by test name, including specifying one parameter on one test and another parameter on another test within the same execution.

    • Using data objects that are linked to an external file - Test data from external sources (e.g. CSV, DB etc.) can be passed to one or multiple tests using the Config file. The parameters can be placed either within the return section (i.e., Execution level) or inside the overrideTestData object (i.e., Test level). The test can be run using the CLI, while adding a flag to use the config file in this run.

  • Through the Params File - The Params File is a JSON file that includes parameters and their values. It is a simpler way to override the data set that was defined in the visual editor. However, it offers Execution level scope only. This means that all the parameters and their values will be used across all the tests included in the execution. The test can be run using the CLI, while adding a flag to use the Params file in this run. The CLI command will pass the parameters to the tests that are included in the run.

📘

The test data size must not surpass 2 MB.

Viewing test runs with different data sets

Test results are separately displayed for each data set, while displaying the data set that was used in the run.

  1. Go to Suite runs view and go to the suite that you just run.
  2. You can see the run result with the Data Set per test when you hover the "i" icon in the right side of the test and then click the See Data Set button.

Setting Cookies

If you need cookies to be loaded before your system loads or you need cookies for a particular test, you can also define cookies using the reserved cookies parameter. The cookies parameter can be added through the visual editor and through the Config file.

Read all about the setting cookies options here.