我正在学习 BDD,行为驱动开发,虽然我抓住了系统行为示例的“想法”,我们可以执行这些示例并通过我们可以开发它,但我陷入了如何正确编写场景(使用 gherking)旨在简化自然语言到步骤之间的过渡..
让我们看看吧。我目前在注册服务部门工作。
我目前的问题就在这块:
Scenario: Successful registration
Given that a user wants to register
And is not registered
When he enters his credentials
And they are correct
Then the system should register him
分为以下步骤...
@Dado("that a user wants to register")
public void que_un_usuario_desea_registrarse() {
name = "Marcos";
surname = "Perez";
email = "[email protected]";
cardId = "23432423";
marcos = new User(name,surname,email,cardId);
}
@Dado("is not registered")
public void no_esta_registrado() {
fakeDB.removeIfExists(marcos);
}
@Cuando("he enters his credentials")
public void introduzca_sus_credenciales() {
// This is an empty space because i have no idea of what should be in
}
@Cuando("they are correct")
public void estas_sean_correctas() {
logUpService.logUp(name, surname, email, cardId, fakeDB);
}
@Entonces("the system should register him")
public void el_sistema_deberia_registrarlo() {
assertEquals(marcos.hashCode(), fakeDB.persisted.hashCode());
}
我尝试过改变需求的表达方式,但我仍然坚持
像“用户想要注册”这样的无软件的事情如何一步步实现?
虽然我使用一种测试替身(称为“fakeDB”),它返回与日志服务(称为“logUpService”)发送到其“存储”组件相同的用户实例,但我不太确定如果这是断言“Then”子句的最佳方式。
我对了解这一点非常感兴趣,所以我很乐意阅读您的建议。