HelloCuriosity / model-forge

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

Home Page:https://hellocuriosity.github.io/model-forge/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

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

Feeling Adventurous πŸ’₯

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:1.4.0.xx-SNAPSHOT")
}
Groovy
repositories {
    maven { url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' }
}

dependencies {
    testImplementation 'io.github.hellocuriosity:model-forge:1.4.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 (snapshot)
  • UInt (snapshot)
  • ULong (snapshot)
  • UShort (snapshot)
  • 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

About

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

https://hellocuriosity.github.io/model-forge/

License:MIT License


Languages

Language:Kotlin 82.6%Language:JavaScript 11.2%Language:Shell 2.4%Language:CSS 2.2%Language:Makefile 1.6%