我试图了解Gherkin,以至于我可以分离出用户故事并允许业务专家编写它们。
如果我有一个背景(第1版),这是一个常见的先决条件,为什么我的所有方案都出现错误,告诉我“多个步骤定义匹配”,这不是背景要点吗?
如果我有不同的Given语句(第1版),那么基于不同的起始位置,后面的时间不应该允许相同的动作吗?同样,“何时”导致“多个步骤定义匹配”
这是我的功能文件。理想情况下,我想要的是版本1,这是业务专家如何编写它们,它们是分开的,易于阅读的,但是要使它工作而又没有“多个步骤定义匹配”错误的唯一方法是版本2,其中每个“当”需要组合时,更复杂,更难阅读。
为什么我不能在超过1种情况下使用Background?
这些被迫改变的气味,所以我在做什么错,我错过了什么?我找到了数百个简单的示例,但我感到我缺少某种小黄瓜的指导原则。我想念什么?
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
我试图了解Gherkin,以至于我可以分离出用户故事并允许业务专家编写它们。如果我有一个背景(第1版),这是一个常见的先决条件,那么为什么要全部...
您的步骤有多个定义。黄瓜每步只允许一个步定义。根据您的描述,您似乎为每种情况都提供了一个步骤定义,因此这两种情况都有各自的When the user says help
定义。这是定义步骤定义的错误方法。每个步骤应该只有一个定义,因此会出现错误。
感谢大家的回答。我也去过黄瓜松弛的支持渠道,在所有这些想法中,一分钱都掉了。