【发布时间】:2019-09-07 22:12:38
【问题描述】:
在进行行为驱动开发时,是否有一种标准方法来决定如何在简单测试和过多测试之间进行权衡?
我正在为一个新项目实施 BDD,最近我通读了 John Smart 的 BDD In Action 一书。本书建议不要混合使用When 和Then 步骤。这似乎会导致更多的测试,从简单的角度来看这可能是可取的,但可能会增加运行测试所需的时间。
我正在考虑如下场景:
Given that a user exists with the following details:
first name | email
Bill | bill@example.com
When I submit the forgot password form
Then bill@example.com should receive a forgot password email
And the email body should contain Bill
When I visit the password reset link
And I use ;v'H~N0et,)S}*VX@fQH9=sm@i1jw|'f as my new password
Then I should be logged in
When I log out
And I log in with password ;v'H~N0et,)S}*VX@fQH9=sm@i1jw|'f
Then I should be logged in
这显然混合了多个 When 和 Then 步骤,但替代方案有 3 个场景:
Given that a user exists with the following details:
first name | email
Bill | bill@example.com
When I submit the forgot password form
Then bill@example.com should receive a forgot password email
And the email body should contain Bill
Given that I have a password reset email
When I visit the password reset link
And I use ;v'H~N0et,)S}*VX@fQH9=sm@i1jw|'f as my new password
Then I should be logged in
Given that I have a password reset email
When I visit the password reset link
And I use ;v'H~N0et,)S}*VX@fQH9=sm@i1jw|'f as my new password
When I log out
And I log in with password ;v'H~N0et,)S}*VX@fQH9=sm@i1jw|'f
Then I should be logged in
有没有推荐的方法来实现这样的测试?在这种场景中混合步骤可以吗?
也许解决方案是确保场景之间的重置过程不会显着影响测试,但如果我们需要在每次测试之间重置数据库,这可能会很困难。
【问题讨论】:
标签: testing integration-testing bdd