我刚刚开始使用 GWT 方法来练习 BDD,然后才意识到我无法进行第二次测试。
我的 GWT 类似于
Given there exists an open query
When the user replies to the query
Then it should save the reply if the reply is not blank
然后它应该通知用户并且如果它是空白的则不保存回复
所以我把它编码成这样
public class when_user_replies_to_the_query : OpenQuery
{
Because
{
query.Reply(data);
}
ThenIt should_save_the_reply_to_the_database_if_there_is_a_reply
ThenIt should_notify_the_user_if_there_is_no_text_in_the_reply_and_not_save_to_database
}
public class Query
{
void Reply(string data)
{
//do something
}
}
但后来我意识到我不能做第二种情况,因为第一种情况要求数据中有一些东西,而第二种情况说数据应该是一个空字符串。
这是否意味着我应该将我的 GWT 拆分为类似
Given the reply is blank
When the user replies to the query
Then it should notify the user ......
如果是这种情况,那么我将编写大量的空案例场景以供返回
values being null. Such as
Given the database is null
When retrieving queries
Should reply with error message
When saving queries
Should save to file and reply with error message
When // basically doing anything
Should //give appropriate response
这是我应该如何编写 BDD 规范的方式吗?我什至在正确的论坛 O_O 中吗?