
BDD extensions for Kotest enabling expressive Given/When/Then and Expect tests, type-safe DSL, built-in data-driven row() parameterization, and concise And chaining.
A Kotlin Multiplatform library that provides Behavior Driven Development (BDD) extensions for Kotest. Write expressive tests using Given/When/Then or Expect syntax across JVM, iOS, macOS, Linux, and Windows platforms. Though it is true Kotest has a BehaviorSpec, they are kind of hard to read with lots of nesting. This is a simple setup that just allows you to label each section of your test.
row() functionThis package is published to Maven Central, so you can add it to your project as follows:
dependencies {
testImplementation("dev.ktool:kotest-bdd:VERSION")
}Replace VERSION with the latest version from the releases page.
Because of changes to Kotest, you have to use the correct major version corresponding to your version of Kotest.
| Kotest Version | Kotest BDD Version |
|---|---|
| 5.x.x | 1.x.x |
| 6.x.x | 2.x.x |
Create a test class extending BddSpec:
import dev.ktool.kotest.BddSpec
import io.kotest.matchers.shouldBe
class CalculatorSpec : BddSpec({
"adding two numbers" {
Given
val a = 5
val b = 3
When
val result = a + b
Then
result shouldBe 8
}
})For simpler tests, you can use the Expect syntax instead of When/Then:
class SimpleSpec : BddSpec({
"validating user input" {
Given
val email = "user@example.com"
Expect
email.contains("@") shouldBe true
}
})Use the row() function for parameterized tests:
class MathSpec : BddSpec({
"multiplication table"(
row(2, 3, 6),
row(4, 5, 20),
row(7, 8, 56)
) { (a, b, expected) ->
Given("two numbers $a and $b")
When("they are multiplied")
val result = a * b
Then("the result should be $expected")
result shouldBe expected
}
})Chain multiple conditions with And:
class UserSpec : BddSpec({
"user registration" {
Given
val user = User("john", "john@example.com")
And
user.email.contains("@") shouldBe true
When
val registered = userService.register(user)
Then
registered shouldBe true
}
})The library enforces proper BDD structure:
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
A Kotlin Multiplatform library that provides Behavior Driven Development (BDD) extensions for Kotest. Write expressive tests using Given/When/Then or Expect syntax across JVM, iOS, macOS, Linux, and Windows platforms. Though it is true Kotest has a BehaviorSpec, they are kind of hard to read with lots of nesting. This is a simple setup that just allows you to label each section of your test.
row() functionThis package is published to Maven Central, so you can add it to your project as follows:
dependencies {
testImplementation("dev.ktool:kotest-bdd:VERSION")
}Replace VERSION with the latest version from the releases page.
Because of changes to Kotest, you have to use the correct major version corresponding to your version of Kotest.
| Kotest Version | Kotest BDD Version |
|---|---|
| 5.x.x | 1.x.x |
| 6.x.x | 2.x.x |
Create a test class extending BddSpec:
import dev.ktool.kotest.BddSpec
import io.kotest.matchers.shouldBe
class CalculatorSpec : BddSpec({
"adding two numbers" {
Given
val a = 5
val b = 3
When
val result = a + b
Then
result shouldBe 8
}
})For simpler tests, you can use the Expect syntax instead of When/Then:
class SimpleSpec : BddSpec({
"validating user input" {
Given
val email = "user@example.com"
Expect
email.contains("@") shouldBe true
}
})Use the row() function for parameterized tests:
class MathSpec : BddSpec({
"multiplication table"(
row(2, 3, 6),
row(4, 5, 20),
row(7, 8, 56)
) { (a, b, expected) ->
Given("two numbers $a and $b")
When("they are multiplied")
val result = a * b
Then("the result should be $expected")
result shouldBe expected
}
})Chain multiple conditions with And:
class UserSpec : BddSpec({
"user registration" {
Given
val user = User("john", "john@example.com")
And
user.email.contains("@") shouldBe true
When
val registered = userService.register(user)
Then
registered shouldBe true
}
})The library enforces proper BDD structure:
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.