Extensions that make working with the JVM BDD testing tool jgiven and Kotlin even more fun.
<dependency>
<groupId>io.toolisticon.testing</groupId>
<artifactId>jgiven-kotlin</artifactId>
<version>1.3.0.0</version>
<scope>test</scope>
</dependency>
when using kotlin, instead of
given()
.some_facts()
`when`() // when is a keyword in kotlin
.something_happens()
then()
.expect_a_result()
you can simply use the dynamic extension properties:
GIVEN
.some_facts();
WHEN
.something_happens()
THEN
.expect_a_result()
(written in CAPS to avoid keyword conflicts).
In jgiven-java, you have to do:
class MyStage extends Stage<MyStage> {
MyStage my_step() {
// what the step does
return self();
}
}
jgiven-kotlin introduces the inline extension function step()
, so this can be simplified to:
@JGivenKotlinStage
class MyStage : Stage<MyStage>() {
fun `my step`() = step {
// what the step does
}
}
Since all classes and functions are final by default in kotlin, you have to explicitly mark everything you write in a Stage to be open
.
Using the JGivenKotlinStage
annotation and kotlin's "all-open" compiler plugin, this can be avoided.
plugins {
id("org.jetbrains.kotlin.plugin.allopen") version "${kotlin_version}"
}
//...
allOpen {
annotation("io.toolisticon.testing.jgiven.JGivenKotlinStage")
}
<plugin>
<!-- Kotlin compiler -->
<artifactId>kotlin-maven-plugin</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
<configuration>
<compilerPlugins>
<plugin>all-open</plugin>
</compilerPlugins>
<pluginOptions>
<option>all-open:annotation=io.toolisticon.testing.jgiven.JGivenKotlinStage</option>
</pluginOptions>
</configuration>
<!-- ... -->
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-allopen</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
</plugin>
- These helpers where moved from jgiven-addons for better separation of concerns and simplified publishing.
- This extension might become obsolete once jgiven supports this officially.