Model Forge is a library to automate model generation for automated testing:
- unit
- integration
- etc.
Kotlin
dependencies {
testImplementation("io.github.hellocuriosity:model-forge:0.9.0")
}
Groovy
dependencies {
testImplementation 'io.github.hellocuriosity:model-forge:0.9.0'
}
If you're feeling adventurous you can be on the cutting edge and test a snapshot:
Kotlin
repositories {
maven(url = "https://s01.oss.sonatype.org/content/repositories/snapshots/")
}
dependencies {
testImplementation("io.github.hellocuriosity:model-forge:0.9.0.xx-SNAPSHOT")
}
Groovy
repositories {
maven { url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' }
}
dependencies {
testImplementation 'io.github.hellocuriosity:model-forge:0.9.0.xx-SNAPSHOT'
}
data class Employee(
val id: Long,
val name: String,
val dob: Instant,
)
val forge = ModelForge()
val testObject = forge.build<Employee>()
or by delegating
val testObject: Employee by forgery()
You can create different sized lists by specifying the number of elements.
val forge = ModelForge()
val list = forge.buildList<TestObject>(3)
or by delegating
val testObjects: List<TestObject> by forgeryList()
While Model Forge aims to fully automate model generation, you may run into an instance where you need to customize your data. This is easily achievable by defining a custom provider and adding it to the forge.
val testProvider: Provider<TestObject> = Provider {
Employee(
id = 15L,
name = "Josh",
dob = Instant.ofEpochMilli(1315260000000)
)
}
forge.addProvider(TestObject.class,testProvider);
or Kotlin
forge.addProvider(testProvider)
Alternatively you can add your forgery providers inline
val forge = ModelForge().apply {
addProvider {
Employee(
id = 2L,
name = "Hendrik",
dob = Instant.ofEpochMilli(1574486400000)
)
}
}
val employee by forgery<Employee>(forge)
Model Forge currently supports the auto generation for the following types:
- Boolean
- Byte
- Calendar
- Char
- Date
- Double
- Enums
- File
- Float
- Int
- Instant
- Long
- Short
- String
- UUID
- List
- Map
- Set
Can't find your data type? Feel free to create a pull request or open an issue πͺ
If you contribute to Model Forge, please feel free to add yourself to the list!
- Kyle Roe - Maintainer
- Adriaan Duz - Contributor
- Kotlin class definitions
- Forgery and forgeries property delegate
- Reified inline extension functions
- Alicja Kozikowska - Contributor
- Fix StringProvider treatment of invalid wordCount