制定正确的场景短语
Formulate correct scenario phrase
我想知道下面的 Gherkin 短语是否符合 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
?
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
对于Thens(结果),我很喜欢"should"这个词。它鼓励人们质疑它;它真的应该发生吗?现在?在这个版本中?是否有任何背景不应该发生这种情况或应该发生不同的事情?它是否还会发生,或者这种情况已经改变?
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.
使用 "should" 这个词也有助于区分一个场景的结果和另一个场景的给定结果;通常这些与形成另一个场景背景的结果重叠:
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.
我想知道下面的 Gherkin 短语是否符合 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
?
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
对于Thens(结果),我很喜欢"should"这个词。它鼓励人们质疑它;它真的应该发生吗?现在?在这个版本中?是否有任何背景不应该发生这种情况或应该发生不同的事情?它是否还会发生,或者这种情况已经改变?
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.
使用 "should" 这个词也有助于区分一个场景的结果和另一个场景的给定结果;通常这些与形成另一个场景背景的结果重叠:
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.