Faker: a library to generate fake data for Java and Android

When writing tests for your application, it's common to make up data to fill your objects. You made up bogus names, emails, dates, addresses, prices... so that your validations still pass and you have realistic test cases. The same thing happens when you're trying to fill a QA database with fake information.

For ruby, I always used the faker gem. It has a big library of different fake data, already translated to more than 30 languages. So I decided to port it to Java, so I could use it in Android development. And here it is:

The goals were:

  • Reuse all the translated data
  • Keep the interface simple and close to the original

With Bruno's help, we ended up implementing all the major features we wanted.

How to install it:

repositories {
    // ...
    maven { url 'https://jitpack.io' }
}

dependencies {
    compile 'com.github.blocoio:faker:1.0.1'
}

And some examples of what you can do with it:

Faker faker = new Faker();
faker.name.firstName();        // "Aaron"
faker.company.name();          // "Hirthe-Ritchie"
faker.address.countryCode();   // "PT"
faker.commerce.price();        // "31.89"
faker.internet.email();        // "[email protected]"
faker.lorem.sentence();        // "Dolore illum animi et neque accusantium."
faker.number.number(10);       // "1968353479"
faker.app.version();           // "2.5.4"

Faker faker = new Faker("nl");
faker.name.firstName();        // "Thijs"

You can get all the information on the Readme.