Test your Clikt cli with a convenient extension function:
class Greeter : CliktCommand() {
override fun run() {
val name = prompt("Enter your name")
echo("Hello $name!")
}
}
Greeter().test {
expectOutput("Enter your name: ")
provideInput("Tester")
expectOutput("Hello Tester!")
}
Clikt Testkit provides a testing dsl for the Clikt command line parser library. Compared to testing with vanilla Clikt, you benefit from
- Easier setup.
Just call
.test{}
on the command you want to test and start writing assertions. No.parse()
, catchingProgramResult
or overwriting the context to set environment variables. - Functions to assert on console output and provide console input in your test.
Clikt Testkit is published through Maven Central. You can include it in your Gradle project by adding this dependency:
dependencies {
implementation("com.wolpl.clikt-testkit:clikt-testkit:1.0.0")
}
For instructions how to implement tests, please refer to the Clikt Testkit documentation.
Clikt Testkit is a Kotlin Multiplatform library, currently supporting these targets:
- JVM
- Native (linuxX64, mingwX64, macosX64)