Initialize instances of any class with generated data.
Inspired by Cesar Ferreira's RxPeople, I thought I'd implement an abstraction of the idea, so you could generate random instances of any class.
This is great for demoing your app with interesting content, manually testing it with varying data, and even populating it with smart, random generated data in production.
In your build.gradle
, add the following:
dependencies {
implementation 'com.mitteloupe:randomgen:1.4.1'
}
To include the default data generators, also include
dependencies {
implementation 'com.mitteloupe:randomgen.datasource:1.0.1'
}
Note: To add the BinTray repository in your maven repositories, also add the following:
repositories {
maven {
url "https://dl.bintray.com/shadowcra/RandomGen"
}
}
RandomGen<ObjectClass> randomGen = new RandomGen.Builder<ObjectClass>()
.ofClass(ObjectClass.class)
.withField("id")
.returningSequentialInteger()
.withField("uuid")
.returningUuid()
.build();
val randomGen = RandomGen.Builder<ObjectClass>()
.ofClass(ObjectClass::class.java)
.withField("id")
.returningSequentialInteger()
.withField("uuid")
.returningUuid()
.build()
This will create a RandomGen
instance producing ObjectClass
instances with sequential IDs and random UUIDs.
To use the newly generated RandomGen
, simply call:
ObjectClass instance = randomGen.generate();
val instance = randomGen.generate()
MIT © Eran Boudjnah