Skip to content

kotlin_jvm_test

Host-side Kotlin tests for the Java virtual machine.

Description

Compiles Kotlin test sources, scans the resulting classes for zero-argument test methods, and emits normalized Once test results. Methods whose names begin with test run without an external test framework. The runner also recognizes the org.junit.Test annotation from JUnit and the kotlin.test.Test annotation when their libraries are on the dependency classpath.

Test Attributes

AttributeTypeRequiredDefaultDescription
test_classstringnoFully qualified class or Class#method filter
argslist<string>no[]Additional class or Class#method filters
jvm_flagslist<string>no[]Flags passed to the Java virtual machine before the test classpath
envmap<string,string>no{}Environment variables applied before test_env
env_inheritlist<string>no[]Host environment variable names to inherit
test_envmap<string,string>no{}Environment variables applied last
labelslist<string>no[]Labels exposed during test discovery
timeout_msintegernoOptional test timeout in milliseconds
javastringnohost toolOverride the Java runtime path
javacstringnohost toolOverride the Java compiler used for the reflection runner

The compiler attributes from kotlin_jvm_library also apply.

Dependency Edges

EdgeAcceptsDescription
depskotlin_jvm_library, java_libraryLibraries used for compilation and runtime
associateskotlin_jvm_libraryFriend modules whose internal declarations are visible during compilation
exported_depskotlin_jvm_library, java_libraryLibraries propagated to compile and runtime classpaths
provided_depskotlin_jvm_library, java_libraryLibraries available only while compiling
runtime_depskotlin_jvm_library, java_libraryLibraries available only while running tests

Providers

The target emits kotlin_jvm_test and once_test_info.

Capabilities

CapabilityOutput groups
testdefault, test_results, logs

Outputs

OutputLocation
Normalized results.once/out/<target>/test-results/test_results.json
Test log.once/out/<target>/test-results/kotlin-jvm-test.log
Native results.once/out/<target>/test-results/native_results.txt

Example

toml
[[target]]
name = "GreetingTests"
kind = "kotlin_jvm_test"
srcs = ["src/test/kotlin/**/*.kt"]
deps = ["./Greeting"]

[target.dependencies]
runtime_deps = ["./TestRuntime"]

[target.attrs]
labels = ["unit"]
test_class = "dev.once.greeting.GreetingTest"

Run all selected methods with once test GreetingTests. Pass a Class#method value through test_class or args for a narrower run.

Limitations

The reflection runner does not implement test framework lifecycle hooks, parameterized tests, sharding, retries, or coverage collection. Frameworks can still supply assertions and annotations through normal dependencies.

Released under an open-source license.