1

I would like to know, if the following Gherkin phrase correspond to BDD rules:

final class KafkaSpec extends BddSpec {

  feature("Kafka distribution to SAP server via websocket") {

    scenario("Kafka consumer does not receive messages from Kafka server") {
      Given("Kafka server is NOT active")
      When("consumer client get started")
      val ex = SenderActor.run
      Then("print message `Failed to connect to Kafka`")
      ex.failed map { ex =>
        assertThrows[ConnectException](ex)
      }
    }

    scenario("Kafka consumer receives messages from Kafka server") {
      Given("Kafka server is ACTIVE")
      When("consumer client get started")
      Then("print message `Successfully connected to Kafka`")
      succeed
    }

  }
}  

Do I use the right tense? Do I use the Given-When-Then correctly?

softshipper
  • 32,463
  • 51
  • 192
  • 400

1 Answers1

2

The Givens (contexts) are fine; we normally use either continuous present or past tense for those:

Given the kafka server is active <-- continuous present
Given the kafka server was started <-- past tense

For the Whens (events), it's better if you can use an active voice. Active voice starts with who did it. Who started the server? (I've corrected the English a bit here too.)

When the consumer client was started <-- passive voice
When our consumer starts their client <-- active voice

For the Thens (outcomes), I really like the word "should". It encourages people to question it; should it really happen? Now? In this release? Is there any context for which this shouldn't happen or something different should happen? Should it still happen, or has this scenario changed?

Then the consumer interface should print the message, `Successfully connected to Kafka`.

One other thing though: the detail in that last step feels a bit too much to me. If the message changed, you'd have to change it everywhere. Instead I keep that in the code (you can abstract the step out) and would say something like:

Then the interface should tell the consumer that the connection was successful.

This is something we usually call "declarative over imperative". It's also OK to have the passive voice here:

Then the consumer should be told that the connection was successful.

Using the word "should" also helps differentiate between the outcomes of one scenario and the givens of another; often these overlap with an outcome forming the context for another scenario:

Given Priscilla has an account
When she enters her username and password correctly
Then she should be on her home page.

Given Priscilla is on her home page...

I wrote more about tenses and language of BDD here, where you'll also find tons of other resources for new BDDers under the BDD category.

Lunivore
  • 17,277
  • 4
  • 47
  • 92