-->
Data-driven testing is an approach for software testing in which test data is stored in a table or spreadsheet format. It also allows testers to input a single test script that could execute tests for all test data from a table and expect the test output in the same table.
The data-driven framework is an automation testing framework in which input values are read from data files and stored in two variables in test scripts. Testers are enabled to build both positive and negative test cases into a single test. We can store input data in the data-driven framework in single or multiple data sources.
Data-driven testing is important because testers typically have several collections of data for a single test, and it can be very time-consuming to construct individual tests for each set. Data-driven automation testing helps us in keeping data separate from test scripts.
The same test scripts could then be executed for different combinations of input test data, and test results could be generated efficiently.
Example:
Here is an example of doing so if we want to test the login system with multiple input fields with a thousand different data sets. We can take the following different approaches for testing this.
Create 1000 scripts, one for each data set, and run each test separately one by one.
Manually adjust the value in the test script and run it several times.
Importing data from the Excel sheet. Fetching test data from Excel rows one by one and executing the script. In the given scenarios, the first two hours are laborious and time-consuming. Hence it is ideal for us to follow the third approach.
Let’s consider that we want to test the login functionality of an application:
Identifying test cases.
Creating detailed testing Steps for the 3 test cases above.
Test Case | Description | Test Steps | Test Data | Results Expected |
1 | Checking Login for valid credentials | Launching the applicationEntering Username passwordClick on OkayCheck Results | Username: valid password: valid | Login Success |
2 | Checking Login for invalid credentials | Launching the applicationEntering Username passwordClick on OkayCheck Results | Username: invalid password: valid | Login Fail |
3 | Checking Login for invalid credentials | Launch the applicationEnter Username passwordClick OkayCheck Results | Username: valid password: invalid | Login Fail |
Creating a test script.
If we observe, the test steps remain common throughout the test steps. It would help if we created a test script for executing this step.
// This is Pseudo Code
// Test Step 1: Launch Application
driver.get(“URL of the Application”);
// Test Step 2: Enter Username
txtbox_username.sendKeys(“valid”);
// Test Step 3: Enter Password
txtbox_password.sendKeys(“invalid”);
// Test Step 4: Check Results
If (Next Screen) print success else Fail
Creating an Excel/CSV with the input test data.
Modifying the script for looping over input test data. The input commands are also required to be parameterized.
// This is Pseudo Code
// Loop 3 Times
for (i = 0; i & lt; = 3; i++) {
// Read data from Excel and store into variables
int input_1 = ReadExcel(i, 0);
int input_2 = ReadExcel(i, 1);
// Test Step 1: Launch Application
driver.get(“URL of the Application”);
// Test Step 2: Enter Username
txtbox_username.sendKeys(input_1);
// Test Step 3: Enter Password
txtbox_password.sendKeys(input_2);
// Test Step 4: Check Results
If(Next Screen) print success
else Fail
}
The three cases above are the ones that the test script could use to loop over the following test cases by appending test data values to Excel.
Below are the best data-driven test practices:
Here are some advantages of Data-Driven Testing:
Here are some disadvantages of Data-Driven Testing:
Output data can be stored in one or more data repositories, including XLS, XML, CSV, and databases, as part of a data-driven test automation framework. A long and time-consuming process is used to construct a single test for each data set.
The Data-Based Research Framework addresses this problem by distinguishing data from practical testing. It is an excellent way to use practical knowledge in data-driven research. It enables several data sets to be evaluated during a regression test.
Related Articles