Keploy logo
Kotlin logo

Keploy as a Kotlin testing framework

Keploy tests Kotlin services by recording real HTTP and JDBC traffic from a running JVM process, then replaying it as assertions. There are no MockK stubs to declare, no coEvery blocks to keep in sync, and no Testcontainers Docker requirement in CI.

Generate Kotlin tests free
keploy record -c "java -jar build/libs/orders.jar"
18.4K+VS Code1.2M+300M+mocks created

What Keploy gives a Kotlin team

Any Kotlin JVM service, unchanged

Keploy runs the JAR Gradle builds. Ktor, Spring Boot with Kotlin, Micronaut, and Http4k all record the same way, because capture happens at the socket rather than inside the framework or the coroutine dispatcher.

  • Kotlin 1.8 and above on the JVM
  • Ktor, Spring Boot, Micronaut, Http4k
  • Coroutines and blocking code alike
  • No test source set changes
The problem

Why Kotlin integration tests slow teams down

The friction is rarely the assertions. It is everything around them — spinning up dependencies, keeping mocks honest, and repairing tests after every refactor.

Three ways to do it

Testing Kotlin: by hand, with JUnit 5 + MockK, or with Keploy

MockK stubs and a Ktor MockEngine are both written from your model of a dependency. Keploy records what the dependency actually returned, so a stub cannot quietly diverge from it.

Select any row for the full comparison, with code.

Same coverage, three costs

What you write for Kotlin vs what Keploy records

All three produce the same assertion. Only the third still passes after the next refactor without anyone editing it.

By hand2–4 hours
OrderServiceTest.kt
hand-written
// Hand-written: interfaces and fakes exist only for this test.
package com.acme.orders
 
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlinx.coroutines.test.runTest
 
class FakeOrderRepo : OrderRepo {
override suspend fun get(id: String) = Order(id, 4200, "NEW")
}
 
class FakePayments : Payments {
override suspend fun authorize(token: String) = "AUTHORIZED"
}
 
class OrderServiceTest {
@Test
fun `confirms an authorized order`() = runTest {
val service = OrderService(FakeOrderRepo(), FakePayments())
 
val result = service.confirm("ord_1", "tok_123")
 
assertEquals("CONFIRMED", result.state)
}
}

Two interfaces exist in production code purely so these fakes can be substituted, and neither fails when the real contract changes.

JUnit 5 + MockK1–2 hours
OrderServiceMockkTest.kt
tool-assisted
// JUnit 5 + MockK + Ktor MockEngine.
package com.acme.orders
 
import io.mockk.coEvery
import io.mockk.mockk
import kotlinx.coroutines.test.runTest
 
class OrderServiceMockkTest {
// Relaxed: an undeclared call returns a default instead of failing.
private val repo = mockk<OrderRepo>(relaxed = true)
private val payments = mockk<Payments>()
 
@Test
fun `confirms an authorized order`() = runTest {
coEvery { repo.get("ord_1") } returns Order("ord_1", 4200, "NEW")
coEvery { payments.authorize("tok_123") } returns "AUTHORIZED"
 
val result = OrderService(repo, payments).confirm("ord_1", "tok_123")
 
assertEquals("CONFIRMED", result.state)
}
}

Concise and coroutine-aware — and the payment contract is whatever the coEvery line claims, while the relaxed repo hides any call nobody declared.

With Keploy~5 minutes
test-1.yaml
auto-generated
# Recorded with: keploy record -c 'java -jar build/libs/orders.jar'
# No MockK stub. No MockEngine. No coroutine scaffolding.
version: api.keploy.io/v1beta1
kind: Http
name: test-1
spec:
req:
method: POST
url: /orders/ord_1/confirm
body: '{"paymentToken":"tok_123"}'
resp:
status_code: 200
body:
id: "ord_1"
state: "CONFIRMED"
amountMinor: 4200
confirmedAt: "2026-09-02T11:04:18Z"
noise:
- body.confirmedAt
mocks:
- kind: SQL
operation: "SELECT id, amount_minor, state FROM orders WHERE id = ?"
- kind: Http
url: https://api.payments.example.com/v1/payment_intents/tok_123/confirm
status: 200

Every suspend function on the path actually ran, so a call nobody thought to declare cannot silently return a relaxed default.

Times are estimates for authoring one endpoint’s coverage from scratch, not measurements.

Keploy vs the alternatives

Kotlin testing tools, compared

The options a team on the JVM actually reaches for, and where each one genuinely wins. Select a row for the full comparison.

Best in classStrongPartialNot covered

Assessments reflect each tool’s documented behaviour, not benchmark measurements.

How it works

Record your Kotlin app once, replay it forever

Keploy sits below your Kotlin process at the network layer. It watches the calls your app already makes, then serves them back on replay so tests run with no dependencies attached.

Keploy records a GET call to /api/v1/orders/{id} on a Kotlin service and captures the dependency calls it makes.

An example shape of a captured call. Your own endpoints and dependencies come from your real traffic, so nothing here has to be written by hand.
Mock coverage

What Keploy mocks for Kotlin, with zero config

7 of the 7 dependencies a typical Kotlin service talks to are stubbed from the recording itself — no mock classes, no fixture files, no containers in CI.

Quick start

Your first Kotlin test suite in under five minutes

Every command below runs against your existing Kotlin service. Nothing in your source tree changes.

  1. 1Install the Keploy CLI

    A single binary. It needs a Linux kernel with eBPF support, or Docker on macOS and Windows — and it adds nothing to your project's dependencies.

    curl -sSL https://keploy.io/install.sh | bash
  2. 2Record your service

    Pass the command you already use to start the app. Keploy runs it and watches every socket it opens.

    keploy record -c "java -jar build/libs/orders.jar"
  3. 3Exercise the paths you care about

    Build as normal, then drive the JAR. Every request becomes a test case with its JDBC and HTTP client calls captured alongside.

    ./gradlew build
    curl -X POST localhost:8080/orders/ord_1/confirm -H 'Content-Type: application/json' -d '{"paymentToken":"tok_123"}'
  4. 4Replay in CI

    Replay serves the recorded dependency responses, so the job needs no service containers and no Docker daemon.

    keploy test -c "java -jar build/libs/orders.jar" --delay 15

Ready to try it on your own Kotlin service?

Ecosystem

Works with the rest of your Kotlin stack

Keploy records at the network layer, so framework and driver choices inside your Kotlin app do not change how it captures traffic.

FAQ

Kotlin testing with Keploy: common questions

Join our GlobalCommunity

Connect with developers worldwide. Follow updates, ask questions, share feedback, and ship faster with other Keploy builders.

1.2M+Installs
18.4K+GitHub
100K+Devs
300M+Mocks
1K+Contributors
#1OSS Trending
4.9★★★★★from 500+ reviews onG2GartnerVS CodeChrome
★★★★★

Best report of integration and API tests I've seen — which we don't get from RestAssured.

G2
★★★★★

Future of microservices testing. I don't write tests now!

G2 · 5/5
★★★★★

An amazing product that simplifies the automation.

Gartner · 4.0
XGitHubSlackYouTubeLinkedIn
Built by developers, for developers.Let's build the future, together.