【发布时间】:2019-10-16 12:27:09
【问题描述】:
我正在努力了解 Gherkin,足以让我能够分离出用户故事并让业务专家编写它们。
如果我有一个背景(版本 1),这是一个常见的前提条件,为什么我的所有场景都会收到错误消息,告诉我“多步骤定义匹配”,这不就是背景的意义,对所有人来说都是通用的吗?
如果我有不同的 Given 语句(版本 1),那么后面的 When 是否应该允许基于不同的起始位置执行相同的操作?同样,When 会导致“多个步骤定义匹配”
这是我的功能文件。理想情况下,我想要版本 1,这就是业务专家编写它们的方式,分开,易于阅读,但在没有“多步骤定义匹配”错误的情况下使其正常工作的唯一方法是版本 2,其中每个 When 需要组合,更复杂,更难阅读。
为什么我不能在超过 1 个场景中使用背景?
这些强制更改很臭,所以我做错了什么,我错过了什么?我找到了数百个简单的例子,但我觉得我缺少某种 Gherkin 的指导原则。我错过了什么?
Feature: Help
When users says help
"As a user
I want the bot to understand me when I ask for help,
In order that I get some guidance, or some idea what to do next"
# Version 1
Background:
Given the user is in conversation with the bot
*// above line causes error*
Scenario: No topic
Given there is no topic
When the user says help
*// above line causes error*
Then the bot responds with a sorry, regretful message
And then asks if the user would like to see a list of available features
Scenario: A valid topic
Given there is a valid topic
When the user says help
*// above line causes error*
Then the bot responds with a confirmation message
And then asks if the user would like to see a list of topic features
# Version 2
# Scenario: All
# Given the user is in conversation with the bot
# When the user says help and there is no topic
# Then the bot responds with a sorry, regretful message
# And then asks if the user would like to see a list of available features
# When the user says help and there is a valid topic
# Then the bot responds with a confirmation message
# And then asks if the user would like to see a list of topic features
Failures:
1) Scenario: No topic # features/help.feature:10
✖ Given the user is in conversation with the bot
Multiple step definitions match:
the user is in conversation with the bot - tests/feature_definitions/help_definition.js:4
the user is in conversation with the bot - tests/feature_definitions/help_definition.js:21
- Given there is no topic # tests/feature_definitions/help_definition.js:7
✖ When the user says help
Multiple step definitions match:
the user says help - tests/feature_definitions/help_definition.js:10
the user says help - tests/feature_definitions/help_definition.js:27
- Then the bot responds with a sorry, regretful message # tests/feature_definitions/help_definition.js:13
- And then asks if the user would like to see a list of available features # tests/feature_definitions/help_definition.js:16
2) Scenario: A valid topic # features/help.feature:16
✖ Given the user is in conversation with the bot
Multiple step definitions match:
the user is in conversation with the bot - tests/feature_definitions/help_definition.js:4
the user is in conversation with the bot - tests/feature_definitions/help_definition.js:21
- Given there is a valid topic # tests/feature_definitions/help_definition.js:24
✖ When the user says help
Multiple step definitions match:
the user says help - tests/feature_definitions/help_definition.js:10
the user says help - tests/feature_definitions/help_definition.js:27
- Then the bot responds with a confirmation message # tests/feature_definitions/help_definition.js:30
- And then asks if the user would like to see a list of topic features # tests/feature_definitions/help_definition.js:33
【问题讨论】:
-
有多个步骤定义,其正则表达式匹配每个场景中的一个或多个步骤。您使用哪种语言来实施步骤?好像你有两种方法来实现
When the user says help。 -
我正在使用 cucumber-js。必须在全局范围内唯一地描述所有内容似乎非常有限制。您是否花费所有时间向业务用户解释他的用户故事需要以不同的方式编写,因为我无法在不更改与之匹配的小黄瓜功能描述的情况下更改黄瓜定义,而且我不是在编写小黄瓜功能.
-
如果同一步骤需要两个不同的定义,那么听起来您需要两个不同的测试项目。您是否分别为 Web 应用程序和 Web API 编写黄瓜测试?
-
请包括您用于这些步骤的步骤定义。
标签: javascript bdd gherkin cucumberjs