“Ahh, Just One More Thing…”

Whoops, I Forgot Something

If you read yesterday’s post, I forgot to mention a theory that, if the steps are granular enough, it’s possible to find duplicate tests.

If two tests perform the same actions in roughly the same order, there’s a pretty good chance they’re similar enough that either one can be gotten rid of (if it’s actually a duplicate), or, they can be combined into a single test, such as in a Scenario Outline.

Cucumber offers a –dry-run option, which goes through the tests but doesn’t actually run any of the code. This is helpful for making sure that you have all your steps defined before committing to the time spent on an actual run.

As part of the dry run, Cucumber will print out the filename and line number of the step definitions, just like it does when you do an actual run.

I think that a little bit of text processing of that output will say what steps were called, in what order, and offer some insight.

If I have this test:

Given I log into the Intergalactic Wholesale Parts shop
When I enter "Fusion Chamber" into the search box
And I click the search button
And I click the 1st view button
And I click on the Add to Cart button
And I click the Payments link
And I enter "Zaphod" into the first name field
And I enter "Beeblebrox" into the last name field
And I enter my intergalactic credit card number into the credit card number field
And I click on the Purchase button
Then I verify that the confirmation message says "Thank you for your purchase, Zaphod! Your delivery will arrive in 3-6 Earth weeks."

And I have this other test:

Given I log into the Intergalactic Wholesale Parts shop
When I enter "Towels" into the search box
And I click the search button
And I click the 1st view button
And I click on the Add to Cart button
And I click the Payments link
And I enter "Ford" into the first name field
And I enter "Prefect" into the last name field
And I enter my intergalactic credit card number into the credit card number field
And I click on the Purchase button
Then I verify that the confirmation message says "Thank you for your purchase, Ford! Your delivery will arrive in 2-4 Earth weeks."

And a dry run tells me the step definitions were found in these files/lines:

common-steps.rb:2  # logging in
common-steps.rb:16 # entering text
common-steps.rb:35 # clicking
common-steps.rb:35 # clicking
common-steps.rb:35 # clicking
common-steps.rb:35 # clicking
common-steps.rb:16 # entering text
common-steps.rb:16 # entering text
common-steps.rb:16 # entering text
common-steps.rb:35 # clicking
common-steps.rb:56 # verifying element text contents

Then that tells me I can probably combine these two tests into a single one, like this:

Given I log into the Intergalactic Wholesale Parts shop
When I enter "<item>" into the search box
And I click the search button
And I click the 1st view button
And I click on the Add to Cart button
And I click the Payments link
And I enter "<firstname>" into the first name field
And I enter "<lastname>" into the last name field
And I enter my intergalactic credit card number into the credit card number field
And I click on the Purchase button
Then I verify that the confirmation message says "<message>"

Examples: 
| item           | firstname | last name  | message                                                                              |
| Towels         | Ford      | Prefect    | "Thank you for your purchase, Ford! Your delivery will arrive in 2-4 Earth weeks."   |
| Fusion Chamber | Zaphod    | Beeblebrox | "Thank you for your purchase, Zaphod! Your delivery will arrive in 3-6 Earth weeks." |

As I find time in the next few weeks, I’ll be experimenting with this idea. Stay tuned!

Advertisements

One thought on ““Ahh, Just One More Thing…”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s