Skip to content

Getting started

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.

Installation

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:

<dependency>
    <groupId>net.datafaker</groupId>
    <artifactId>datafaker</artifactId>
    <version>1.4.0</version>
</dependency>
dependencies {
    implementation 'net.datafaker:datafaker:1.4.0'
}
dependencies {
    implementation("net.datafaker:datafaker:1.4.0")
}
<dependency org="net.datafaker" name="datafaker" rev="1.4.0"/>

Snapshot versions

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:

repositories {
    mavenCentral()
    maven(url = "https://s01.oss.sonatype.org/content/repositories/snapshots")
}

dependencies {
    implementation("net.datafaker:datafaker:1.5.0-SNAPSHOT")
}

Usage

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
import net.datafaker.Faker

val faker = Faker()

val name = faker.name().fullName() // Miss Samanta Schmidt
val firstName = faker.name().firstName() // Emory
val lastName = faker.name().lastName() // Barton

val 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.

Back to top