Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Testing

Status: 🟡 Partial — kargo test runs JVM tests and accepts --target and --filter. --coverage, --report, --parallel, --repeat, --fail-fast, and flavor selection are ⚪ planned. See Implementation Status.

Running tests

kargo test
     Compiling my-service v1.2.0 (jvm, dev)
       Running 24 tests
test com.example.OrderTest.rejects_empty_order ... ok
test com.example.OrderTest.applies_discount ... ok
…

test result: ok. 24 passed; 0 failed; 0 skipped; finished in 0.31s

Tests live in src/test/kotlin for JVM projects, or src/commonTest/kotlin and src/<target>Test/kotlin for multiplatform ones. No registration needed — anything in those directories is a test source.

Selecting what to run

kargo test --filter OrderTest                 # one class
kargo test --filter com.example.orders         # a package prefix
kargo test --filter rejects_empty_order        # one test
kargo test --target jvm                        # one target

--filter matches against the fully qualified test name as a substring, so a package prefix, a class name, and a method name all work.

Test dependencies

[dev-dependencies]
kotlin-test = "org.jetbrains.kotlin:kotlin-test:2.4.21"
mockk = "io.mockk:mockk:1.13.9"
assertj = "org.assertj:assertj-core:3.25.1"

[dev-dependencies] are on the test compile and runtime classpath and nowhere else. They are not published and not in your application's runtime graph.

For multiplatform, put common test dependencies in [dev-dependencies] and platform-specific ones under the target:

[dev-dependencies]
kotlin-test = "org.jetbrains.kotlin:kotlin-test:2.4.21"

[target.jvm.dependencies]
junit = { group = "org.junit.jupiter", artifact = "junit-jupiter", version = "5.10.1", scope = "test" }

Frameworks

kotlin-test works out of the box and is what the templates use. On the JVM it delegates to JUnit, so JUnit 5 annotations, extensions, and parameterized tests all work:

import kotlin.test.Test
import kotlin.test.assertEquals

class OrderTest {
    @Test
    fun `applies discount to totals over 100`() {
        assertEquals(90.0, Order(total = 100.0).withDiscount(0.1).total)
    }
}

Backtick test names are idiomatic Kotlin and Kargo reports them verbatim.

Coverage

Status: ⚪ Planned. [test.coverage] parses today; --coverage is not implemented.

[test.coverage]
engine = "kover"                 # or "jacoco"
min-line = 80
min-branch = 70
exclude = ["**/generated/**", "**/BuildConfig.*"]
kargo test --coverage
kargo test --coverage --open     # open the HTML report

Reports land in build/reports/coverage/ as HTML plus an XML file in Cobertura/JaCoCo format for CI ingestion. Falling below a threshold fails the command, which is what makes it useful as a gate.

EngineUse when
koverKotlin-native, understands inline functions and multiplatform. The default.
jacocoJVM-only, when existing tooling expects JaCoCo output.

Exclude generated code. Coverage of code you did not write is noise, and BuildConfig in particular will never be covered.

Test reports

Status: ⚪ Planned.

kargo test --report junit,html
FormatOutputFor
consolestdoutHumans. The default.
junitbuild/reports/tests/junit.xmlCI annotations and history.
htmlbuild/reports/tests/index.htmlBrowsing failures locally.

Parallelism and flakiness

Status: ⚪ Planned.

kargo test --parallel          # run test classes concurrently
kargo test --repeat 3          # run each test three times
kargo test --fail-fast         # stop at the first failure

--repeat is the flake detector: a test that passes once and fails once in the same run is flaky, not broken by your change.

Testing flavored projects

Status: ⚪ Planned — depends on flavors reaching the build path.

kargo test --flavor free
kargo test --variant paid-staging

Each variant compiles its own BuildConfig, so tests that assert on configuration run against the right values per variant.

Multiplatform tests

kargo test --target jvm
kargo test --target ios-simulator-arm64

Common tests in src/commonTest/kotlin compile and run against every target; target-specific tests in src/jvmTest/kotlin run only there. Native test execution needs the matching host — iOS simulator tests require macOS.

Benchmarks

Status: ⚪ Planned.

kargo bench
kargo bench --compare main

Runs kotlinx-benchmark benchmarks, writing JSON results to build/reports/benchmarks/. --compare diffs against a stored baseline so a regression shows up as a number rather than a feeling.

In CI

kargo test --report junit --coverage

See Continuous Integration for complete workflow examples.

Next