【发布时间】:2020-08-26 22:25:48
【问题描述】:
我正在探索使用 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
我怎么能在 behave 中做这样的事情?我在考虑也许使用given、when 和then 装饰器inside step_impl 函数...
【问题讨论】:
标签: bdd python-behave