Data-Driven Testing
- Understanding Data-Driven Testing (DDT)
- Putting It into Practice with Playwright and Python
- Advantages and Limitations
Data-Driven Testing is a testing approach where the same test logic is executed with different sets of input data and expected results. It can be performed manually or through automation, but it is commonly used in automated testing frameworks, where test data is supplied externally through Excel sheets, CSV files, database tables, etc.
Data-Driven Testing is ideal when the test logic remains the same but the input data changes. The main goal is to verify that the application behaves as expected for each data set. For example, a login page can be tested using a valid username and password, a valid username and an invalid password, an invalid username and a valid password, or both an invalid username and password.
Get Jayani Basnayake’s stories in your inbox
Join Medium for free to get updates from this writer.
To put this approach into practice, I created a login testing project using Playwright, Python, and a CSV file. Using pytest parameterisation, I ran the same test function with different test data and checked the outcome for each scenario.
You can explore the code and test data in my GitHub repository and try it yourself.
However, in a real-world project, one of the most vital parts of data-driven testing is the test data itself. This data can come in several formats, including CSV files, Excel sheets, and XML documents.
It needs to be extracted, parsed into a structured format that the test scripts can use, and validated for quality. Potential issues include missing or corrupted files, inconsistent inputs, duplicate records, and unintended missing values. However, intentionally empty or invalid values should be kept when they are needed to test validation behaviour.
Each execution uses assertions to compare actual and expected outcomes. Expected results can be stored in the data source or defined in the test code.
Can data-driven testing be used in every project? Let’s explore its advantages and limitations to understand when it is a suitable approach.









