在我的BDD场景中,自动化Then步骤的设计问题



我对BDD还很陌生,我正在尝试使用BDD为网站开发一个简单的注册模块

我有以下场景

Scenario: An anonymous visitor successfully signs up with the website  
Given the following email address: john.smith@gmail.com and a chosen member status of childminder and the following password: ------ 
When the anonymous visitor signs up  
Then a confirmation email with activation information is sent to the anonymous visitor

我非常不知所措自动执行Then步骤("然后向匿名访问者发送一封包含激活信息的确认电子邮件")

以下是我(与JBehave)所做的工作:

@Given("the following email address: $email and a chosen member status of $status and the following password: $password")
public void anonymousVisitorEntersDetails(String email, String status, String password) {
    pages.home().open();
    pages.home().enterDetails(email, status, password);
}
@When("the anonymous visitor signs up")
public void anonymousVisitorDoesRegister(String login, String password) {
    pages.home().doRegister();
}
@Then("a confirmation email with activation information is sent to the anonymous visitor")
public void activationInformationIsSent() {
    //TODO ??
}

我的问题与其说是工具问题,不如说是设计问题。如果有经验丰富的BDD从业者能帮我解决这个问题,我将不胜感激。。。

让我们从Given开始。这设置了上下文。如果我了解您的情况,可能感兴趣的相关事项包括:-未登录-在主页(或注册)上此处不要提及用户详细信息。

接下来,When步骤指定匿名用户注册的用户详细信息。

最后,然后步骤需要检查是否发送了确认电子邮件。尽管发送电子邮件是很诱人的&检查它是否到达,这将是IMO的一个错误。电子邮件不能保证到达,而且在任何情况下都很慢。保持测试套件的快速性和健壮性。

相反,使用When语句的措辞,或场景中的标签,来指示您的应用程序应该使用模拟电子邮件组件构建。在Then步骤中,您可以询问mock,以验证它是否已按预期调用。

在测试中,您仍然需要进行集成和/或验收测试,以验证"真实"电子邮件组件是否已正确部署。这可能是手动测试,也可能是一个缓慢的&temperamental自动测试,登录到邮件客户端并进行轮询,直到收到包含预期内容的电子邮件。

最新更新