When doing Behavior Driven Development, is there a standard way to decide how to make the tradeoff between simple tests and too many tests?
I'm working on implementing BDD for a new project, and I've recently read through the book BDD In Action by John Smart. The book recommends not intermixing When
and Then
steps. This seems like it would likely result in more tests, which may be desirable from a simplicity perspective but could increase the amount of time tests take to run.
I'm considering a scenario like the following:
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
This obviously intermixes multiple When
and Then
steps, but the alternative is having 3 scenarios:
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
Is there a recommended way to implement a test like this? Is it OK to intermix the steps in this type of scenario?
Maybe the solution is to make sure the reset process between scenarios doesn't contribute significantly the testing, but this could be difficult if we need to reset the database between each test.