kotlin-faker: the ultimate fake data generation library for development and testing
Kotlin-faker is a comprehensive data-generation library for the JVM. It is most suitable for development, testing, and data anonymization purposes, and can be used with Kotlin, Java, Android, Scala, and other JVM-based projects. Kotlin-faker provides realistic-looking, fake data generation capabilities in various domains like names, addresses, internet, banking, books, games, and many more.
In fact, kotlin-faker is so good at generating fake data, it almost fooled us into thinking it was real! 🤯
From names that sound like they belong to secret agents🕴️, to addresses where superheroes 🦸♂️
and villains 🦹 might live.
Use kotlin-faker during development and testing to ensure your application data looks as if it was real,
just like this really fake logo, but not quite so.
Kotlin-faker is a kotlin port of a popular ruby faker gem.
⚠️ P.S. All names, addresses, bank accounts, and other data generated by this library - even those based on real strings - are entirely fictional. All produced data is fake and generated... poorly. The data is completely made up, but the problems that it tries to solve are real. We take no responsibility for any existential crises caused by the eerily convincing fake data. Use with caution! ⚠️
Some of the bits that kotlin-faker gives you are…
…a plethora of real-looking data in various domains:
val faker = Faker()
faker.name.nameWithMiddle() // => Dr. John Abrams Smith
faker.address.streetAddress() // => 474 Kilback Manor
faker.internet.safeEmail() // => chance.marvin@yahoo.test
val faker = CommerceFaker()
faker.bank.swiftBic() // => AACCGB21
val faker = BooksFaker()
faker.book.genre() // => Fantasy
val faker = MoviesFaker()
faker.starWars.characters() // => Darth Vader
val faker = TvShowsFaker()
faker.friends.characters() // => Phoebe Buffay
// a total of 213 different data providers
…in 60 locales:
val config = fakerConfig { locale = "nb-NO" }
val faker = Faker(config)
faker.address.city() // => Høyberg
faker.name.nameWithMiddle() // => Sofie Ødegård Løken
…“unique data generation”:
val faker = Faker()
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)
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()
class Foo(val a: String)
class Bar(val foo: Foo)
val foo: Foo = faker.randomClass.randomClassInstance()
val bar: Bar = faker.randomClass.randomClassInstance()
class Baz(val id: Int, val uuid: UUID, val username: String)
val baz: Baz = faker.randomClass.randomClassInstance {
// ヽ(^o^)丿 ᕕ(ᐛ)ᕗ Prepend string type parameter values with parameter name!
typeGenerator<String> { parameterInfo -> "${parameterInfo.name}_${randomString()}" }
typeGenerator<UUID> { UUID.fromString("00000000-0000-0000-0000-000000000000") }
typeGenerator<Int> { faker.random.nextInt(min = 0, max = 9) }
}
assertEquals(baz.username, "username_X3a8s813dcb")
assertEquals(baz.uuid, UUID.fromString("00000000-0000-0000-0000-000000000000"))
assertTrue(baz.id in 0..9)
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
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.