kotlin-faker

kotlin-faker is a data-generation library intended for use during development and testing, as well as for data-anonymization purposes.
It generates realistically looking fake data within a variety of different domains such as names, addresses, banking details, movies, games, and many more. Just like this fake logo, but not quite so.


Some of the bits that kotlin-faker gives you are…

…a plethora of real-looking data in various domains:

val faker = Faker()
Names
faker.name.nameWithMiddle() // => Dr. John Abrams Smith
Addresses
faker.address.streetAddress() // => 474 Kilback Manor
Internet
faker.internet.safeEmail() // => chance.marvin@yahoo.test
Banking
faker.bank.swiftBic() // => AACCGB21
Books
faker.theExpanse.ships() // => Rocinante
Movies and TV
faker.starWars.characters() // => Darth Vader
faker.friends.characters() // => Phoebe Buffay
…and many others
// a total of 171 different data providers

…in 57 locales:

val config = fakerConfig { locale = "nb-NO" }
val faker = Faker(config)
nb_NO -> city
faker.address.city() // => Høyberg
nb_NO -> person‘s name
faker.name.nameWithMiddle() // => Sofie Ødegård Løken

…“unique data generation”:

val faker = Faker()
Generate unique values within a domain
faker.unique.configuration {
    // enable generation of unique values for address data provider
    enable(faker::address)
}
val countries = List(100) { faker.address.country() }
assertEquals(countries.distinct().size, 100)
Generate unique values within a function
val countries = List(100) { faker.address.unique.country() }
val cities = List(1000) { faker.address.city() }
assertEquals(countries.distinct().size, 100)
assertTrue(cities.distinct().size < 1000)

…cli native app for looking up data generators:

faker-bot lookup name --verbose
#Faker()
#├── address
#│   ├── cityName() // => Port Olinstad
#│   ├── countryByName() // => NR
#│   └── streetName() // => Lance Roads
#├── animal
#│   └── name() // => gnat
#├── app
#│   └── name() // => Bamity
#├── artist
#│   └── names() // => Cezanne
#├── bank
#│   └── name() // => ABN AMRO HOARE GOVETT SECURITIES
#├── beer
#│   └── name() // => Oaked Arrogant Bastard Ale
# rest of output that matches query

…and more:

val faker = Faker()
Random instance of any class…
class Foo(val a: String)
class Bar(val foo: Foo)

val foo: Foo = faker.randomProvider.randomClassInstance()
val bar: Bar = faker.randomProvider.randomClassInstance()
…with pre-configured type generation
class Baz(val id: Int, val uuid: UUID, val name: String)

val baz: Baz = faker.randomProvider.randomClassInstance {
    typeGenerator<UUID> { UUID.fromString("00000000-0000-0000-0000-000000000000") }
    typeGenerator<Int> { faker.random.nextInt(min = 0, max = 9) }
    typeGenerator<String> { faker.name.name() } // Random name generated by Faker
}
assertEquals(baz.uuid, UUID.fromString("00000000-0000-0000-0000-000000000000"))
assertTrue(baz.id in 0..9)
String templates
faker.string.numerify("foo###bar") // foo123bar
faker.string.letterify("foo???bar", true) // fooXYZbar
faker.string.bothify("foo?##bar", false) // foox42bar
faker.string.regexify("""\d{2}\w""") // 42a
Random numbers, strings, enums, UUIDs, and more…
faker.random.nextInt(intRange = 0..1000)
faker.random.nextLong(bound = 999L)
faker.random.randomString(length = 99)
faker.random.nextEnum<TestEnum>()
faker.random.nextEnum(TestEnum::class.java) {
    it != TestEnum.SOME // Exclude 'SOME' enum
}
faker.random.nextUUID()

See the pages under the User Guide section, jump straight to the Getting Started page, or explore the Data Provider API or the Full Core API documentation to learn more.