我想知道,以下小黄瓜短语是否符合BDD规则:
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
}
}
}
我使用正确的时态吗?我可以正确使用Given-When-Then
吗?
答案 0 :(得分:2)
Givens(上下文)很好;我们通常将连续现在或过去时用于这些情况:
Given the kafka server is active <-- continuous present
Given the kafka server was started <-- past tense
对于Whens(事件),最好使用主动语音。主动语气始于谁。谁启动了服务器? (我也在这里对英语做了一些更正。)
When the consumer client was started <-- passive voice
When our consumer starts their client <-- active voice
对于那么(结果),我真的很喜欢“应该”这个词。它鼓励人们质疑它。它真的应该发生吗?现在?在这个版本中?是否有不应该发生这种情况或应该发生其他事情的环境?应该还是会发生,还是这种情况发生了改变?
Then the consumer interface should print the message, `Successfully connected to Kafka`.
不过,另一件事:最后一步的细节对我来说感觉太过分了。如果消息更改,则必须在任何地方进行更改。相反,我将其保留在代码中(您可以抽象出该步骤),并说类似以下内容:
Then the interface should tell the consumer that the connection was successful.
这通常称为"declarative over imperative"。也可以在此处使用被动语气:
Then the consumer should be told that the connection was successful.
使用“应该”一词还有助于区分一种情况的结果与另一种情况的结果;通常,这些结果与结果重叠在一起,形成了另一种情况的背景:
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,您还可以在the BDD category下找到用于新BDD的大量其他资源。