Quick testing tips #8


Use BehaviorSpec to write BDD style test




import io.kotest.core.spec.style.BehaviorSpec

class SomeOtherSpec : BehaviorSpec({
  Given("some preconditions") {
    When("action is executed") {
      Then("expect result") {}
    }
    When("other action is executed") {
      Then("expect other result") {}
    }
  }
})



Want to write BDD style test with Given-When-Then structure? Make use of BehaviorSpec to put test code in DSL. You can have multiple When branches in one Given block and reuse some logic.



Read next:


Loading ...
Failed to load data.