Javascript 小黄瓜多步骤定义匹配
我试图理解小黄瓜,足以让我把用户故事分离出来,让业务专家来写 如果我有一个背景(版本1),一个共同的前提条件,为什么我的所有场景都会出现错误,告诉我“多步骤定义匹配”,这不是背景的要点,对所有人来说都是共同的吗 如果我有不同的给定语句(版本1),那么接下来的When不应该基于不同的起始位置允许相同的操作吗?同样,When会导致“多个步骤定义匹配” 这是我的特征文件。理想情况下,我想要版本1,这是业务专家编写它们的方式,分开,易于阅读,但要使其工作而不出现“多步骤定义匹配”错误,唯一的方法是版本2,其中每个步骤都需要组合,更复杂,更难阅读 为什么我不能在多个场景中使用背景 这些被迫的改变很难闻,那么我做错了什么,我错过了什么?我已经找到了数百个简单的例子,但我觉得我缺少了一些小黄瓜的指导原则。我错过了什么Javascript 小黄瓜多步骤定义匹配,javascript,bdd,gherkin,cucumberjs,Javascript,Bdd,Gherkin,Cucumberjs,我试图理解小黄瓜,足以让我把用户故事分离出来,让业务专家来写 如果我有一个背景(版本1),一个共同的前提条件,为什么我的所有场景都会出现错误,告诉我“多步骤定义匹配”,这不是背景的要点,对所有人来说都是共同的吗 如果我有不同的给定语句(版本1),那么接下来的When不应该基于不同的起始位置允许相同的操作吗?同样,When会导致“多个步骤定义匹配” 这是我的特征文件。理想情况下,我想要版本1,这是业务专家编写它们的方式,分开,易于阅读,但要使其工作而不出现“多步骤定义匹配”错误,唯一的方法是版本2
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
您的步骤有多个定义。Cucumber只允许每个步骤定义一个步骤。从您所描述的内容来看,您似乎为每个场景提供了一个步骤定义,因此当用户说“帮助”时,这两个场景都有自己的
定义。这是定义步骤定义的错误方法。每个步骤应该只有一个定义,因此您将得到错误
当用户说帮助时,的定义应适用于使用此步骤的所有场景。它的定义应该是通用的
如果同一步骤确实需要根据场景而有所不同,您有两个选项:
创建一个单独的测试项目,这样就可以有两个全局唯一的定义,因为步骤定义将有两个单独的全局上下文
参数化步骤
参数化步骤可能是最简单的,当用户说“帮助”时,我将使用作为示例:
Scenario: No topic
Given there is no topic
When the user says "help"
Then the bot responds with a sorry, regretful message
And then asks if the user would like to see a list of available features
上面的一行将单词help
放在双引号内。生成步骤定义将允许您将引号之间的文本作为参数传递给步骤定义方法:
When(/the user says "([^"]+)"/, function(textToSay) {
// "speak" to the chat bot using whatever API you have defined
chatBot.receiveMessage(textToSay);
});
现在,这一步可以接受多段文本:
When the user says "help"
...
When the user says "list topics"
...
When the user says "I WANT TO SPEAK TO A REAL PERSON!!!!"
Then the bot responds with "I'm sorry, Dave. I'm afraid I can't do that."
(好的,我做了最后一步,但如果机器人不明白用户在说什么,那将是一个有趣的回答)您的步骤有多个定义。Cucumber只允许每个步骤定义一个步骤。从您所描述的内容来看,您似乎为每个场景提供了一个步骤定义,因此当用户说“帮助”
时,这两个场景都有自己的定义。这是定义步骤定义的错误方法。每个步骤应该只有一个定义,因此您将得到错误
当用户说帮助时,的定义应适用于使用此步骤的所有场景。它的定义应该是通用的
如果同一步骤确实需要根据场景而有所不同,您有两个选项:
创建一个单独的测试项目,这样就可以有两个全局唯一的定义,因为步骤定义将有两个单独的全局上下文
参数化步骤
参数化步骤可能是最简单的,当用户说“帮助”时,我将使用作为示例:
Scenario: No topic
Given there is no topic
When the user says "help"
Then the bot responds with a sorry, regretful message
And then asks if the user would like to see a list of available features
上面的一行将单词help
放在双引号内。生成步骤定义将允许您将引号之间的文本作为参数传递给步骤定义方法:
When(/the user says "([^"]+)"/, function(textToSay) {
// "speak" to the chat bot using whatever API you have defined
chatBot.receiveMessage(textToSay);
});
现在,这一步可以接受多段文本:
When the user says "help"
...
When the user says "list topics"
...
When the user says "I WANT TO SPEAK TO A REAL PERSON!!!!"
Then the bot responds with "I'm sorry, Dave. I'm afraid I can't do that."
(好的,我做了最后一步,但如果机器人不明白用户在说什么,那将是一个有趣的回答)谢谢大家的回答。我也去过cucumber slack支持频道,在所有这些想法中的某个地方,便士终于掉了下来
我读过的每个示例都显示了使用步骤定义文件1对1映射的功能文件
在我看来,这些特性在终端窗口中创建了模板,然后我将其放入step.js文件中,这些文件是在测试中运行的文件,它们毕竟是.js!终端模板是重复的,我将它们复制到steps.js 1-to-1中
我没有想到功能文件仍然是流程的一部分,实际上是测试运行时的步骤驱动程序
我现在将我的步骤组织在一个完全不同的文件夹文件结构中,不再是功能文件的1对1,一些我从未见过的示例显示的东西,用户说什么,机器人响应什么,主题等等,这一切现在变得更有意义,当然,它已经删除了所有重复的步骤
再次感谢所有将想法推向正确方向的人:-)谢谢大家的回答。我也去过cucumber slack支持频道,在所有这些想法中的某个地方,便士终于掉了下来
我读过的每个示例都显示了使用步骤定义文件1对1映射的功能文件
在我看来,这些特性在终端窗口中创建了模板,然后我将其放入step.js文件中,这些文件是在测试中运行的文件,它们毕竟是.js!终端模板是重复的,我将它们复制到steps.js 1-to-1中
我没有想到功能文件仍然是流程的一部分,实际上是测试运行时的步骤驱动程序
我现在将我的步骤组织在一个完全不同的文件夹文件结构中,不再是功能文件的1对1,一些我从未见过的示例显示的东西,用户说了什么,机器人响应了什么,主题等等,等等