DDT (Data Driven Testing ) is where we use a file to read and write test data instead of using hard code values. There are few ways to use Data Driven Testing in your project. We can use either a property file or a excel sheet . And today we are going to look at Data Driven Testing using a property file.

Create a property file in your project

  1. First of all create a text file with “.properties” extension in your project
  2. Then write variable names and variable values inside the property file

Property file

If there are more than one value exist for a particular variable separate each value by using a comma. As an example imagine you have three user roles in your system.

e.g. #Login credentials

username = ABC

password = password123

userrole = Admin, Customer, Buyer

Use “#” if you want to comment something in property file.

Setup property file in your project

  • First of all you need to import these packages to read and write data to the property file
    • import java.io.FileInputStream;
    • import java.io.FileNotFoundException;
    • import java.io.IOException;
    • import java.util.Properties;
  • Create an instance of “Properties” class
  • And then write a method to get/read data from the property file
  • Like wise you have to write a method to set/write data into the property file

Capture1

 

We can do the changes to the property file without changing the java class file. Because of that it became an advantage of using a property file.

We reached the end. So hope you have found something valuable in this article. Feel yourself free to drop any questions or comments . And also if you have any struggling technical areas related to software quality assurance send your requests to us. So we can publish article related to those topics in near future. As always keep in touch :).

FacebookTwitterGoogle+LinkedIn