Faking Data for test automation


0 (11).jpeg

You are developing test automation script for your application and need test data or your application has been deployed and the product owner or the business owner comes around the corner. The registration screen loads up but you realise thereโ€™s no data in the system. And you canโ€™t think of any creative customer names besides from โ€œJohn Smithโ€ and โ€œJane Doe.โ€

So you need to useย Java Faker library

The idea behind the library is very simple. It generates fake data. The library actually came out of a software project developed by my companyย DiUS Computing. We used it to generate data for demos or testing.

The following steps will show how to use this library with Java and Maven Project:

For example you need to test Registration form such as this one

1- In your Maven Project add the following dependency in the POM.xml file

<dependency>  
    <groupId>com.github.javafaker</groupId><artifactId>javafaker</artifactId><version>0.5</version>
</dependency>

* check the latest version from maven repository

2- Create an instance of the Faker

Faker fakeData = new Faker();

3- Add Fake data to fill this form with Faker like this snippet

String userName = fakeData.name().username();

String email = fakeData.internet().emailAddress();ย 

// username with max 6 digits 
Stringย  password = fakeData.number().digits(6).toString();

String firtName = fakeData.name().firstName();ย 

String lastName = fakeData.name().lastName();ย 
ย 

Doneย you can now use these fake data in your test and every time will be new data .

for more information you can take a look at theย javadocsย for examples of what fake data can be generated.

References

https://github.com/DiUS/java-faker

 

Good Luck and Happy Testing ๐Ÿ™‚

Get ready to become an Automation Guru!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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