Logo

0x5a.live

for different kinds of informations and explorations.

GitHub - HelloCuriosity/model-forge: Model Forge is a library to automate model generation for automated testing

Model Forge is a library to automate model generation for automated testing - HelloCuriosity/model-forge

Visit SiteGitHub - HelloCuriosity/model-forge: Model Forge is a library to automate model generation for automated testing

GitHub - HelloCuriosity/model-forge: Model Forge is a library to automate model generation for automated testing

Model Forge is a library to automate model generation for automated testing - HelloCuriosity/model-forge

Powered by 0x5a.live 💗

Model Forge 🔥🔨

Build Status codecov License Contributor Covenant Sonatype Nexus (Snapshots) Awesome Kotlin Badge

About

Model Forge is a library to automate model generation for automated testing:

  • unit
  • integration
  • etc.

Getting Started

Gradle Setup

dependencies {
    testImplementation("io.github.hellocuriosity:model-forge:1.5.0")
}
dependencies {
    testImplementation 'io.github.hellocuriosity:model-forge:1.5.0'
}

Feeling Adventurous 💥

If you're feeling adventurous you can be on the cutting edge and test a snapshot:

repositories {
    maven(url = "https://s01.oss.sonatype.org/content/repositories/snapshots/")
}

dependencies {
    testImplementation("io.github.hellocuriosity:model-forge:1.5.0.xx-SNAPSHOT")
}
repositories {
    maven { url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' }
}

dependencies {
    testImplementation 'io.github.hellocuriosity:model-forge:1.5.0.xx-SNAPSHOT'
}

Define your model

data class Employee(
    val id: Long,
    val name: String,
    val dob: Instant,
)

Generate model

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()

Custom Provider

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.

Define your provider

val testProvider: Provider<TestObject> = Provider {
    Employee(
        id = 15L,
        name = "Josh",
        dob = Instant.ofEpochMilli(1315260000000)
    )
}

Add your provider to the forge

forge.addProvider(TestObject.class,testProvider);

or Kotlin

forge.addProvider(testProvider)

Inline your provider(s)

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)

Supported Types

Model Forge currently supports the auto generation for the following types:

Types

  • Boolean
  • Byte
  • Calendar
  • Char
  • Date
  • Double
  • Enums
  • File
  • Float
  • Int
  • Instant
  • Long
  • Short
  • String
  • UByte
  • UInt
  • ULong
  • UShort
  • UUID

Collections

  • List
  • Map
  • Set

Can't find your data type? Feel free to create a pull request or open an issue 🪂

Contributing

Thanks for showing your interest in wanting to improve Model Forge. Before you get started take a look at our code of conduct and contribution guides 🙌

Contributors

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

Kotlin Resources

are all listed below.

Resources

listed to get explored on!!

Made with ❤️

to provide different kinds of informations and resources.