Data-driven testing using Properties files


Data-driven testing is a software testing methodology where test data and/or output values are read from data files instead of using hard-coded values.
Data-driven testing helps to keep data separate from test scripts and the same test scripts can be executed for different combinations of input test data and test results.



A .properties file is a simple text file mainly used in Java to store configuration data. Such files can be used for externalizing test data.
Each line in a .properties file normally contains a single data. Each data is stored as a key-value pair of strings, one storing the name of the data, and the other storing the value.
Several formats are possible for each line, including key=value, key = value, key:value, and key value. Single-quotes or double-quotes are considered part of the string.



.properties file can be used in test automation to store UI elements of an application or a website, test input and expected test results. You can have different .properties files for different data sets.
The advantage of .properties files is that if, for example, something changes in the application UI, you only need to change the relevant .properties file without recompiling the test script.

For the purposes of this document, we will use the TextInputDemo application provided in the Java Tutorials.



Let’s try to create a Maveryx test script in Java that would:
   1. Start TextInputDemo
   2. Set the value of “Street address”
   3. Set the value of “City”
   4. Set the value of “Zipcode”
   5. Click the button “Set address”
To implement a data-driven test case create two .properties files, one storing the UI elements of the application being tested (textInputDemo.properties) and another storing the test data (testData.properties).



To read data from a .properties file use the com.maveryx.util.img.PropertiesManager.readProperty(String, String) method.

At the beginning of the test script load the widgets data from the textInputDemo.properties file:



Then load the test data from the testData.properties file just before performing the test action.



Here there are the test’s methods:



Properties files contain data in Key=Value format. They are widely used in Java apps to store and retrieve (configuration) data.
Data-Driven testing using properties files as test data source is feasible with Maveryx to handle UI elements and test input and results.
By this approach, changes to the tests can be made easily without accessing the source code.


Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

2 thoughts on “Data-driven testing using Properties files

  • Bryan Cox

    Question: How would using a .properties file when there are to be multiple executions but the data is different?

    • Mauro Garofalo Post author

      In case of multiple executions running the same test but with different data, You can create a function that, for the different executions, selects the correct data file to pass to the test case.