How to Conduct Data-driven Testing - All You Need to Know



One of the key offerings of test automation, that we are very thankful for is data-driven testing.

Also known as table-driven testing, or parameterized testing, data-driven testing was created keeping in mind that writing test cases repeatedly for slightly varied versions of similar data would be cumbersome.

Why do we need data-driven testing?

Data-driven test cases are a means with which frequently occurring data sets in an application can be stored and retrieved when needed. You can also get a larger set of data to use the same operation over and over.

Let's understand this with the help of an example:

You are building an application to calculate an individual's age with two fields: Name and Date of birth. It is common knowledge that a name cannot have any special characters, and the variable DOB has to follow a specific format, either with '/, -, or.' to separate the date, month, and year fields. If any other data is input by a user, an appropriate error message should be displayed on the screen.

We proceed to write a test case for the name input field as such:

Name field only accepts the alphabets.

Name field should not accept any numbers.

Name field should not accept any symbols.

Next, we write a test case for the editable date field as such:

The date field should accept the valid month, date, year in mm/dd/yy format.

The date field should not accept the wrong month, year, and date format - yy/dd/mm.

The date field should not accept the input in more than two digits for date andmonth.

The date field should not accept more than four digits for the year.

The date field should not accept a blank input, either whole or for any part of the input.

The date field should not accept any other symbol than '/' or. or '-'.

The date field should not accept special characters and alphabets.

The date field should only accept valid numbers, i.e., from 01-31, in date, 01-12, in month, and 1901-2021(or current year) in year.

The dates should be adjusted to have 30, 31 or 28, 29 days as per calendar month and year.

Now, we have 1000 people who want to input their details into the form to calculate their ages.

We can test this application in three ways:

  1. Whenever a new data set is entered, write separate test scripts, and execute them one at a time.
  2. Whenever you have to run the test case for a different data set, manually change it in the test script. Once done, execute it for all the required numbers of data sets.
  3.  Import the data into an excel sheet or CSV file, fetch this data one by one from the database, and then run the script.

Executing the data-driven test cases using the 1st and 2nd methods is a painfully time-consuming and lengthy process. However, by using the third method, i.e., automating the execution of test scripts for each data set retrieved from the data source, we save 90% of the time. It is a data-driven testing framework ideal for scenarios mentioned above.

Advantages of using data-driven testing.

As seen in the above example, real-life applications are highly dynamic. Data is frequently updated and modified. Therefore, any hard-coded data is impossible to run each time. With the use of tables, large amounts of data are maintained and used seamlessly.

To manually cover all the test scenarios is out of the question. A tester will have to create numerous test scripts and execute each one, which results in a loss of time and effort.

With data-driven test cases, the test data can be retrieved from a table independently without making any changes to the actual test script. Thus, the same test script runs iteratively for multiple data sets.

Here are four benefits of using the data-driven testing method for increasing your software quality:

1.      Multiple sets of data can be tested simultaneously.

One of the critical advantages of utilizing data-driven testing frameworks is the amount of time saved by testing a large volume of data all at once. It is especially helpful when doing regression testing, where the application is tested after every update and modification. It is also why data-driven testing can be performed at any given phase of the software or application's development.

2.      Test case logic is separate from test data.

Another added benefit of data-driven testing is that the test case logic is independent of the data source. The test data and the verification data can be put into one file and kept segregated from the actual test logic. Thus, any changes to the test script will not affect the test data. Data-driven testing allows developers and testers to separate the logic of their test cases/scripts from the test data.

3.      Test scripts are stored in a single repository.

Tests can be efficiently understood, maintained, managed, and executed when the test scripts are stored onto a single point of central storage.

4.      Similar actions and functions can be reused.

When the test cases are run, lots of data is generated automatically. Data-driven frameworks can be tweaked, and test cases can be scripted to replicate actions and functions that produce similar output for saving time.

How does data-driven testing work?

There are six definitive steps involved in the data-driven testing framework:

  1. Create a test case: A test script is written. A data file will contain all the relevant test data that includes positive test cases, negative test cases, and exceptions. 
  1. Parameterize values for input fields: Relevant data fields are added. Data type is specified. The values will be editable by the user.
  1. Download the data source: The data source template will be downloaded with all the parameters used.
  1. Update values to the data source: The template will be supplied with test and verification values.
  1. Add data source to the testing tool: The data source will be uploaded with values to run your test against the test script.
  1. Run test with data source: The test will now be executed for N number of values, and results will be displayed for each individual value.

Takeaways:

Data-driven testing is an absolute necessity when your application has varied input sources. It is, therefore, useful when running tests with new or updated data. Data-driven testing is an essential and highly used facet of test automation. It helps you reduce your testing time by 50-90% and speed up your deployment.

One limitation, however, is that the creation of data-driven testing frameworks is a complicated process, one that needs QA professionals with expertise in scripting data-driven test cases, its languages and other test automation know-hows. When done by a highly skilled testing team, data-driven testing can ensure your software's quality to make it robust and user-friendly.

Post a comment

0 Comments