Dynamic Input Test Data Generation: Best Practices,Random Java API



In Testing it is important to provide input data to complete the execution of Test-cases. Irrespective of any type of testing such as Functional Testing,Integration Testing,System Testing and Performance Testing the input data plays a vital role.
In Automation tools such as Selenium WebDriver the input data can be maintained in three different ways:

1. Maintain parameters in the testng.xml. Read the parameter values using @Parameters annotation.
2. Maintain input data in the Excel File. Read the data and pass the values using @DataProvider annotation.
3. Input Data in the properties file.

In the above 3 cases, the input data stored is static. If we suppose, the dynamic data should be generated used in the execution flow of test cases. We have to Java API to generate the dynamic data.
So, we will go through now how to generate the random/dynamic input data.

Note:
Do not get confuse with the dynamic object properties. In this post we are discussing about only the input data.

Generating two digit Random Number

java.util.Random is a java class available for generating random integers.

Generating three digit Random Number

Generating Random ASCII Character

To generate the random characters we should glance through the ASCII table from this link.
http://www.asciitable.com/

      Lower Case Alphabets– Decimal Number Ranging from 97 to 122
      Upper Case Alphabets– Decimal Number Ranging from 65 to 90

Generating five digit Random Number

Conclusion:

The Dynamic input data generated is useful to execute the test case in different Testing Environment without any dependency on resource files.

Leave a Reply

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