Initialize instances of any class with generated data.
This is a Kotlin port of the Java library designed to 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.randomgenkt:randomgenkt:2.0.1")
}
To include the default data generators, also include
dependencies {
implementation("com.mitteloupe.randomgenkt:randomgenkt.datasource:2.0.1")
}
val randomGen = RandomGen.Builder<ObjectClass>()
.ofKotlinClass<ObjectClass>()
.withField("id")
.returningSequentialInteger()
.withField("uuid")
.returningUuid()
.build()
RandomGen<ObjectClass> randomGen = new RandomGen.Builder<ObjectClass>()
.ofJavaClass(ObjectClass.class)
.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:
val instance = randomGen()
ObjectClass instance = randomGen.invoke();
Version 2.0
This is an overhaul of RandomGenKt. It has been dusted, polished and refactored to align with modern conventions.
--
The Kotlin version adds the following:
- Support for fields with lazy init
- Lambdas
ofClass<Type>()
instead ofofClass(Type::class.java)