Saturday, October 29, 2011

Using properties file

There are a number of ways to perform data driven testing. Here i will mention how to use a properties file to get data and use it for testing purpose.   


        InputStream is = this.getClass().getResourceAsStream("/conf/datasuite.properties"); 
        Properties prop = new Properties(); 
        prop.load(is);
        String directory = prop.getProperty("Directory"); 
        String numberOfFiles = prop.getProperty("NumberOfFiles"); 
        String  fileExtension = prop.getProperty("Extension"); 
        is.close();
       
        System.out.println(directory+" "+numberOfFiles+" "+fileExtension);

Contents of datasuite.properties file.

       Directory = C:/prodFiles/
       NumberOfFiles = 25
       Extension = javaworlddfg


One thing to note is that the 'conf' folder is referenced with respect to the class files created.

No comments:

Post a Comment