-
Notifications
You must be signed in to change notification settings - Fork 234
Home
Testing applications against random input, also known as Monkey Tests, is an essential step to improve their stability and robustness.
There are many use cases where we need to generate random data during tests such as :
- Generating random model to test view rendering in a MVC web application
- Generating random form input to test form validation
- etc
Generating random data is a tedious task, especially when the domain model involves many classes. This is where jPopulator comes to play, to help you populating your domain objects easily with random data.
Many production bugs are due to processing of unexpected data and jPopulator can help you to detect these nasty bugs earlier during development/test phases.
So if you love Monkey tests, jPopulator will be your best friend!
jPopulator is a java tool that allows you to populate java beans with random data. It can be very useful when your domain model involves many classes, since it populates recursively all the "related" types of a given java bean. Let's see an example, suppose you have the following classes:
If you want to populate a Person bean with jPopulator, you simply write this:
Populator populator = new PopulatorBuilder().build();
Person person = populator.populateBean(Person.class);
And voila! jPopulator will introspect the Person type hierarchy, generate an instance for each nested bean and populate it with random data.
Without jPopulator, you would write the following code:
Street street = new Street(12, (byte) 1, "Oxford street");
Address address = new Address(street, "123456", "London", "United Kingdom");
Person person = new Person("Foo", "Bar", "[email protected]", Gender.MALE, address);
And if these classes do not provide constructors with parameters (may be some legacy beans you don't have the control over), you would write:
Street street = new Street();
street.setNumber(12);
street.setType((byte) 1);
street.setName("Oxford street");
Address address = new Address();
address.setStreet(street);
address.setZipCode("123456");
address.setCity("London");
address.setCountry("United Kingdom");
Person person = new Person();
person.setFirstName("Foo");
person.setLastName("Bar");
person.setEmail("[email protected]");
person.setGender(Gender.MALE);
person.setAddress(address);
As you can see, jPopulator can save you from writing all this bean populating code often written "by hand".
Easy Random is created by Mahmoud Ben Hassine with the help of some awesome contributors!