Skip to content

Repository files navigation

Fake

Fake is a Gradle plugin powered by KSP that automatically generates type-safe fake builders for Kotlin data class models — designed for tests only to generate fakes for models while testing.

It works with Kotlin, Android, and Kotlin Multiplatform (KMP) projects.


✨ What it does

Given model:

data class User(
    val id: String,
    val age: Int,
    val tags: List<String>
)

Fake generates:

val user = fakeUser {
    id = "123"
    age = 30
}

📦 Installation

plugins {
    id("io.github.mohaberabi.fakeklass.plugin") version "<version>"
}
dependencies {
    add("kspCommonMainMetadata", "io.github.mohaberabi:fake:<version>")
}

Make sure mavenCentral() is configured.


⚙️ Configuration

Tell FakeKlass which packages contain your models: Generated fakes are available and shipped **only in for the source set you want **.

ksp {
    arg("fake.packages",     
        "com.example.models",
        "com.example.domain")
}

sourceSets {
    commonTest {
        kotlin.srcDir(layout.buildDirectory.dir("generated/ksp/metadata/commonMain"))
    }
}

🧪 Using fakes in tests

@Test
fun createUser() {
    val user = fakeUser {
        age = 42
    }

    assertEquals(42, user.age)
}

About

Fake is a KSP-based code generator that creates type-safe fake builders for Kotlin data classes, designed for testing in Kotlin projects.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages