Skip to content

Latest commit

 

History

History
39 lines (28 loc) · 1009 Bytes

README.md

File metadata and controls

39 lines (28 loc) · 1009 Bytes

Faktory

Jitpack Release

Faktory implements Object Mothers for Kotlin.

When we write tests or demos, it is often necessary to create some example data. Some of those "data beans" are composed of many other objects. Constructing such object graphs by hand is very tedious.

This library helps you write those data bean generators in simple, idiomatic Kotlin code.

Usage

Given following domain entity Post:

data class Post(
    val title: String,
    val body: String,
    val author: Author,
)

data class Author(val name: String)

You can write a custom data factory that generates test data:

val postFactory = factory<Post>()

val post: Post = postFactory.make()
val posts: Iterable<Post> = postFactory.make(3)

You can also customize on per-field basis:

val post = postFactory.make {
    Post::title by { "Hello World!" }
}

post.title // "Hello World!"