This repository is home to Spockk, an add-on for the Spock testing framework that brings its expressive BDD-style syntax for Groovy to Kotlin.
class WelcomeSpec : Specification() {
fun `welcome to Spockk`(visitor: Being, greeting: String) {
given
val spock = Vulcan("Spock")
expect
spock.greet(visitor) == greeting
where
visitor ; greeting
Vulcan("Sarek") ; "Live long and prosper!"
Human("Kirk") ; "Hello!"
}
}The Spock framework for Groovy relies on AST transformations to transform its expressive specification syntax into runnable specification classes. The Spockk add-on achieves a similar behavior by implementing a Kotlin compiler plugin (examples). The following diagram shows the simplified interaction between all the different components that Spockk is composed of.
graph TB
gradle["spockk-gradle-plugin"]
intellij["spockk-intellij-plugin"]
spock["spock-core"]
subgraph compiler["Kotlin Compiler"]
sources["Sources (.kt)"]
frontend["Compiler frontend"]
backend["JVM IR backend"]
plugin["spockk-compiler-plugin"]
bytecode["Bytecode"]
sources --> frontend
frontend -->|generate intermediate representation| backend
backend --> plugin
plugin -->|transform IR into executable tests| bytecode
end
gradle -->|applies spockk-compiler-plugin| compiler
intellij -->|detects specifications and features| sources
spock -->|executes| bytecode
spockk-compiler-plugin: implements IR transformations that modify the simplified test syntax into tests compatible with Spock's test engine.spockk-core: declares additional Kotlin-specific specification syntax.spockk-docs: module with user guide.spockk-gradle-plugin: Gradle plugin that abstracts away the application of thespockk-compiler-pluginto Kotlin compiler invocations.spockk-intellij-plugin: provides support for Spockk tests in IntelliJ.spockk-specs: specifications for the framework written with Spockk.