RandomGenKt
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.
Install
In your build.gradle
, add the following:
dependencies {
implementation("com.mitteloupe.randomgenkt:randomgenkt:1.0.1")
}
To include the default data generators, also include
dependencies {
implementation("com.mitteloupe.randomgenkt:randomgenkt.datasource:1.0.1")
}
Usage
Kotlin
val randomGen = RandomGen.Builder<ObjectClass>()
.ofClass<ObjectClass>()
.withField("id")
.returningSequentialInteger()
.withField("uuid")
.returningUuid()
.build()
Java
RandomGen<ObjectClass> randomGen = new RandomGen.Builder<ObjectClass>()
.ofClass(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:
Kotlin
val instance = randomGen.generate()
Java
ObjectClass instance = randomGen.generate();
What's New?
The Kotlin version adds the following:
- Support for fields with lazy init
- Lambdas
ofClass<Type>()
instead ofofClass(Type::class.java)
Created by
License
MIT © Eran Boudjnah