I am trying to write the first time of my life test based on BDD style as the following:
final class SapRsSpec extends FeatureSpec
with Matchers
with GivenWhenThen {
feature("KAFKA") {
scenario("Technical user starts SAP RS") {
Given("Consumer client gets started")
When("KAFKA server is not active")
Then("message `Can not connect ot KAFKA` appears.")
}
}
}
I was trying to write as a technical user perspective.
Is it correct?
When clause should ideally describe the action and not the state, so writing
When("consumer client gets started")
instead of When("Kafka server is not active") is more idiomatic. Thinking of Given-When-Then as the Hoare triple might be helpful, where we first specify state before the action (Given), then the action that mutates the sate (When), and finally the expected sate after the action (Then).
feature and scenario clauses should ideally make sense on their own even when leaving out Given-When-Then body. Just stating feature("Kafka") seems too broad. The feature being specified is actually the relationship between Kafka and replication server, not just Kafka by itself.
Say the feature being specified is replication server's distribution to Kafka under two scenarios, when Kafka is up and when it is down, then we might refine the spec as follows:
feature("Replication server's distribution to Kafka") {
scenario("Replication server's distribution when Kafka is DOWN") {
Given("Kafka server is NOT active")
When("consumer client gets started")
Then("print message 'Failed to connect to Kafka'")
}
scenario("Replication server's distribution when Kafka is UP") {
Given("Kafka server is active")
When("consumer client gets started")
Then("print message 'Successfully connected to Kafka'")
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With