Data-driven testing is a great way to strengthen your automated testing strategy. By replacing hard-coded values with dynamic values that are loaded at runtime, you can parameterize your tests to run across several inputs and expand your test coverage to include a wider variety of scenarios.
This article introduces the benefits of data-driven testing and helps you choose the best approach for your goals.
Benefits of data-driven testing
There are a number of benefits of making your tests data-driven. Some include:
- Reusability: a single test can be executed multiple times with varying inputs.
- Separation of logic: data-driven tests allow for the clean distinction of test logic from the actual test data.
- Efficiency: you can update data for a test outside of the mabl Trainer or API Test Editor.
- Stronger test coverage: you can continually change the input test data and cover a broad scenario of inputs.
Choosing an approach
mabl supports different forms of data-driven testing. Use the following table to choose the best approach according to your goals:
| Goal | Example | Recommended approach |
|---|---|---|
| Run the same test across different input sets | Validating a page in each localized language | DataTables |
| Reuse a runtime value from one test in a later test | Storing an authentication cookie in a variable and passing it to other runs | Shared variables |
| Same variable name, different value per environment | Using different test data for staging vs. production | Environment variables |
| A fresh/unique value each run | Generating random user data for a checkout flow | Valid expressions: faker, macros |
For a complete list of data-driven variable types and the order of precedence when more than one value is passed to the same variable, see Data-driven variables
DataTables trigger multiple runs
Associating a test with a DataTable runs the test once per scenario (row). For example, a 7-row DataTable produces 7 test runs. A test cannot loop through all DataTable scenarios in one run.