如何解决嵌套方案?场景如何在给定的语句中使用其他Scenerios?
我正在探索使用 behave 测试聊天机器人。
我可以定义简单的场景,例如
Scenario: Asked a widget function question
Given a new dialog
When the visitor asks
"""
What do your widgets do?
"""
Then bot should explain widget function
Scenario: Asked a widget cost question
Given a new dialog
When the visitor asks
"""
How much does your widget cost?
"""
Then bot should provide widget cost
问题是一个好的聊天机器人需要保留上下文。如果成功保存上下文,则顺序很重要。如果以上两种情况均通过,则这并不意味着一个对话框,一个接一个地问这些问题,就不会抛出错误。
为此,您需要一个这样的场景
Scenario: Asked a widget function question and price question
Given a new dialog
When the visitor asks
"""
What do your widgets do?
"""
And the bot explains widget function
When the visitor asks
"""
How much does your widget cost?
"""
Then bot should provide widget cost
当然,为每个要测试的对话框编写一个在Given
块中具有对话框前导的脚本是非常重复的。
我宁愿以某种方式“嵌套”场景。这样的东西(我知道这是无效的)。
Scenario: Asked a widget cost question
Given user Asked a widget function question
When the visitor asks
"""
How much does your widget cost?
"""
Then bot should provide widget cost
我该如何在行为中做类似的事情?我在考虑也许在内部使用given
,when
和then
装饰器 step_impl
函数...
解决方法
使每个先前的消息成为Given
。
Scenario: Asked a widget function question and price question
Given a new dialog
And the visitor already asked
"""
What do your widgets do?
"""
When the visitor asks
"""
How much does your widget cost?
"""
Then bot should provide widget cost
先前问题的Given
语句可以显式等待正确的答案,也可以在继续下一步之前仅等待任何答案。这样,获得小部件价格的先决条件就清楚地表示为Given,这很适合BDD测试的Give-When-Then风格。您也不会用一堆与该场景没有直接关系的Then来弄乱您的场景。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。