Hope you enjoyed reading the blog post and were able to learn about generating random test data from it. This was a brief analysis of some of a few random data generator java libraries available to use and how we could use them to generate test data. ![]() There is not an easy work around for generating a random bean with both random and static values. One problem with using Random Beans to generate test data is that it requires us to create Randomizers for fields that require static values. FakeValuesService faker = new FakeValuesService( new Locale("en-US"), new RandomService()) faker.letterify("12?89") //will return something like "12hZ89" faker.numerify( "ABC#EF") //will return something like "ABC99EF" faker.bothify("12?#ED") //will return something like "12iL27ED" faker.regexify(" Regexify(String regex) method allows us to generate a String that matches the given regular expression. Numerify(String numberString) method allows us to generate random numerical characters for the # characters in the numberString that is passed to numerify().īothify(String alphanumericString) method allows us to generate random alphanumeric characters for the ? and # characters in the alphanumericString that is passed to bothify(). Letterify(String letterString) method allows us to generate random alphabetic characters for the ? characters in the letterString that is passed to letterify(). Java Faker provides us with FakerValueService that in turn contains methods to generate random sequences of letters, numbers and both. When generating json data, Mockaroo will omit keys with null values if this is set to false. To always return an array, specify a value of 'true' for this parameter. The utility allows you to generate JSON data, and export the generated JSON files. When generating json data, Mockaroo will return an array when count > 1 and an object when count is 1. ![]() ![]() In order to use Java Faker in a project, we need to add the following maven dependency to our POM: javafaker 0.17.2 This tool allows you to generate random JSON files from a template. Java Faker can be used to generate a variety of real looking data. We would see how we can use these libraries in conjunction with REST-assured to run an automated functional API test. There are various ways to generate random data in Java, but here we will discuss mainly about Java Faker, JsonTemplate and random-beans libraries.
0 Comments
Leave a Reply. |