Datafaker is a library for Java and Kotlin to generate fake data. This can be very helpful when generating test data to fill a database, to generate data for a stress test, or anonymize data from production services.
The latest version of Datafaker is 1.4.0 and is hosted on Maven Central.
Datafaker can be included in your project using most dependency management tools:
It's also possible to use the latest snapshot version (currently 1.5.0-SNAPSHOT) by including the Sonatype snapshot repository in your configuration.
A Gradle example can be found below:
To use Datafaker to generate fake data, you can use the following code as an example:
import net.datafaker.Faker; Faker faker = new Faker(); String name = faker.name().fullName(); // Miss Samanta Schmidt String firstName = faker.name().firstName(); // Emory String lastName = faker.name().lastName(); // Barton String streetAddress = faker.address().streetAddress(); // 60018 Sawayn Brooks Suite 449
For a full list of all the fake data providers, have a look at the reference documentation.