[go: up one dir, main page]

Skip to content

Test your Clikt cli with a convenient extension function.

License

Notifications You must be signed in to change notification settings

wolpl/clikt-testkit

Repository files navigation

Maven Central Sonatype Nexus (Snapshots)

Clikt Testkit

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(), catching ProgramResult or overwriting the context to set environment variables.
  • Functions to assert on console output and provide console input in your test.

Usage

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.

Multiplatform Support

Clikt Testkit is a Kotlin Multiplatform library, currently supporting these targets:

  • JVM
  • Native (linuxX64, mingwX64, macosX64)