kotlin-ksp-mocks
Build-time recording-spy mocks for Kotlin interfaces, generated by a
KSP processor into the test
compilation only. Nothing is committed, no annotation artifact touches the
main classpath, and the generated member vocabulary matches
swift-sourcery-templates —
one mock dialect for a codebase that tests the same logic on both platforms.
kotlin-ksp-mocks is open source under the MIT license and works in any Gradle
build on its own. Modaal.dev supports this repository and
also makes code and design authoring tools for native iOS and Android apps: the
tools give an agent the project's context and the commands to build, check and
run the app, and let a person design the screens and edit the code beside the
agent.
Agent skill
skills/kotlin-ksp-mocks/ is an
agent skill: the wiring and the
generated API below, written for a coding agent working in a repository that
consumes this processor. It picks the configuration for the module shape —
Kotlin/JVM, multiplatform, Android, a module whose interfaces live elsewhere,
testFixtures — writes the three edits, prints the mock a module generates
without compiling the module, and names the cause when generation fails or a
test collecting a mock's Flow does not terminate.
Four channels install it, over one tree.
1. The cross-agent skills CLI. -g installs for every project on the
machine instead of this one; --list lists without installing.
npx skills add modaal-agent/kotlin-ksp-mocks
2. As a Claude Code plugin. The repository root is the marketplace, and
skills/ is the plugin's root:
/plugin marketplace add modaal-agent/kotlin-ksp-mocks
/plugin install kotlin-ksp-mocks@kotlin-ksp-mocks
/plugin update kotlin-ksp-mocks@kotlin-ksp-mocks installs a new version.
3. By hand.
git clone https://github.com/modaal-agent/kotlin-ksp-mocks
cp -r kotlin-ksp-mocks/skills/* ~/.claude/skills/
.claude/skills/ inside a project installs it for that project alone.
4. claude.ai and the Skills API. The frontmatter carries only the Agent
Skills standard's keys, so skills/kotlin-ksp-mocks/ packages and uploads
unedited.
A prompt to try in a Gradle project:
The tests of :feed use a hand-written FakeFeedRepository. Generate a mock
of FeedRepository instead, rewrite FeedViewModelTest to use it, and assert
that refresh() loads the first page once.
Wiring
The artifact is on neither Maven Central nor Google's repository, so the host
that serves it is declared first:
// settings.gradle.kts
dependencyResolutionManagement {
repositories {
mavenCentral()
maven { url = uri("https://modaal-agent.github.io/maven") }
}
}
Then, in the module whose tests need the mocks:
// build.gradle.kts of the module whose tests need mocks
plugins {
alias(libs.plugins.ksp)
}
dependencies {
kspTest("dev.modaal:mocks-processor:<version>")
// A multiplatform module has no typed accessor for its KSP configuration:
// add("kspJvmTest", "dev.modaal:mocks-processor:<version>")
}
ksp {
arg("kspMocksTargets", "com.example.FeedEnvironment,com.example.FeedDependency")
}
<version> is the <release> element of
https://modaal-agent.github.io/maven/dev/modaal/mocks-processor/maven-metadata.xml.
kspMocksTargets is a comma-separated list of fully-qualified interface
names. Selection is a build-script list rather than an in-source marker by
measurement: an interface declared in main/commonMain reaches the test
compilation's KSP pass as a compiled binary, so no comment or KDoc marker
survives to be read there — and putting an annotation on the main classpath
is exactly what this processor exists to avoid.
Generation lands under build/generated/ksp/… during test compilation and is
never committed: there is no drift to check, and an interface member added in
main fails the next test compile against the regenerated mock.
Generated API
For an interface method, the mock records and seeds with three members:
interface FeedEnvironment {
suspend fun load(id: String): FeedPage
}
val environment = FeedEnvironmentMock()
environment.loadHandler = { id -> FeedPage(id) } // the only seeding mechanism
environment.load("p1")
environment.loadCallCount // 1
environment.loadArgs // ["p1"]