问题描述
我目前正在学习编剧模式,但是我遇到了Given关键字的问题。 对于我当前的用例,似乎应该是一个问题。
Given(user).has(OpenedTheApplication.successfully())
已定义为任务
func has(_ task: Task) {
perform(task)
}
小黄瓜关键字定义如下:
class Given: GherkinKeyword {
func has(_ task: Task) {
actor.has(task)
}
}
因此,如果我正确理解了剧本,则任务不应创建有关系统状态的查询。
所以我想定义一下:
Given(user).wasAbleto(OpenTheApplication.toTheHomePage())
然后
func wasAbleto(_ question: Question) {
ask(question)
}
,同时更新了小黄瓜关键字:
class Given: GherkinKeyword {
func has(_ task: Task) {
actor.has(task)
}
func wasAbleto(_ question: Question) {
actor.wasAbleto(question)
}
}
这是断言应用程序已正确启动的正确思维方式吗?
解决方法
如果要声明任何内容,则应为“ Then”,而不是“ Given”。如果您担心测试所需的设置(Givens)的任何部分可能无法正常工作,那么最好的做法是编写一个单独的测试来检查这些功能。这样一来,您就可以使用所需的任何设置来进行更复杂的测试,而无需在设置(给定)阶段进行断言(问题)。
您需要进行测试的小黄瓜可能看起来像这样:
Scenario: Homepage is presented on app launch
When the user launches the application successfully
Then the user sees the homepage
Scenario: Navigate to search
Given the user has launched the application successfully
When the user navigates to the search page
Then the user sees the search page