An open API service indexing awesome lists of open source software.

https://github.com/pshevche/spockk

Add-on for the Spock testing framework bringing its expressive syntax to Kotlin
https://github.com/pshevche/spockk

kotlin spock-framework testing

Last synced: 3 months ago
JSON representation

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

Awesome Lists containing this project

README

          





Spockk

This repository is home to Spockk, an add-on for the [Spock](https://github.com/spockframework/spock) testing framework
that brings its expressive BDD-style syntax for Groovy to Kotlin.

## Sneak peek

```kotlin
import io.github.pshevche.spockk.lang.then
import io.github.pshevche.spockk.lang.`when`
import io.github.pshevche.spockk.lang.where
import spock.lang.Specification
import kotlin.test.assertEquals

class MathTest : Specification() {
fun `sum of two numbers`(a: Int, b: Int, expectedSum: Int) {
`when`
val sum = a + b

then
assertEquals(expectedSum, sum)

where
a ; b ; expectedSum
1 ; 3 ; 4
7 ; 4 ; 11
0 ; 0 ; 0
}
}
```

## Getting started

- [User guide](https://pshevche.github.io/spockk/)
- [Example project](https://github.com/pshevche/spockk-example)

## 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](https://kotlinlang.org/docs/all-open-plugin.html#0)).
The following diagram shows the simplified interaction between all the different components that Spockk is composed of.

```mermaid
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
```

### Modules

- [`spockk-compiler-plugin`](spockk-compiler-plugin/README.adoc): implements IR transformations that modify the
simplified test syntax into tests compatible with Spock's test engine.
- [`spockk-core`](spockk-core/README.adoc): declares additional Kotlin-specific specification syntax.
- [`spockk-docs`](spockk-docs/README.adoc): module with user guide.
- [`spockk-gradle-plugin`](spockk-gradle-plugin/README.adoc): Gradle plugin that abstracts away the application of the
`spockk-compiler-plugin` to Kotlin compiler invocations.
- [`spockk-intellij-plugin`](spockk-intellij-plugin/README.adoc): provides support for Spockk tests in IntelliJ.
- [`spockk-specs`](spockk-specs/README.adoc): specifications for the framework written with Spockk.