Skip to content

pshevche/spockk

Repository files navigation

Spockk

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.

Sneak peek

import io.github.pshevche.spockk.lang.and
import io.github.pshevche.spockk.lang.given
import io.github.pshevche.spockk.lang.`when`
import io.github.pshevche.spockk.lang.then

import spock.lang.Specification

class MyFirstSpecification : Specification() {
    fun `adding an element to a list`() {
        given
        val myList = mutableListOf<Int>()

        `when`
        myList.add(1)

        and
        myList.add(2)

        then
        assert(myList.size == 2)
    }
}

Getting started

Development

High-level design

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
Loading

Modules

  • 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 the spockk-compiler-plugin to Kotlin compiler invocations.
  • spockk-intellij-plugin: provides support for Spockk tests in IntelliJ.
  • spockk-specs: specifications for the framework written with Spockk.

About

Add-on for the Spock testing framework bringing its expressive syntax to Kotlin

Topics

Resources

License

Stars

Watchers

Forks

Contributors 5

Languages