What makes a feature and what is the scenario for cucumbers and cucumbers?

Let's say I'm designing a shopping basket, BDD, with a cucumber. The cart is quite complex and has many bells and whistles, but it can be just as good for a “blog” or “user profile”.

I always thought that the "cart" is a Feature, and the bells and whistles are a script. However, this can make large function files and contradicts the literal meaning of the script. Here's what it would look like:

Feature: Cart So that I can buy items As a user I want to place items in a cart #.... Many more scenarios Scenario: Empty a filled cart Given 2 products in my cart When I visit the cart page And I press "Empty cart" Then I should see the text: """ Your cart is empty. """ Scenario: Empty an empty cart Given 0 products in my cart When I visit the cart page Then I should not see the "Empty cart" button # Many more Scenario's 

The more details are filled, the longer this empty basket group becomes. I wonder if the "empty cart" should be considered an autonomous feature? This will lead to many functions containing just a few scripts. Then the script becomes more like “contexts”. For instance:

 Feature: Emptying Cart So that I can reconsider my shopping-spree As a user I want to empty my cart Scenario: with a filled cart Given 2 products in my cart When I visit the cart page And I press "Empty cart" Then I should see the text: """ Your cart is empty. """ Scenario: with an empty cart Given 0 products in my cart When I visit the cart page Then I should not see the "Empty cart" button 

What is a good guide for creating something special? When should I regroup a script into my own function? How many features do Scenario usually have?

+6
source share
2 answers

You can shorten your scripts - and even get rid of a few - by formulating them in a declarative, rather than imperative , language.

For instance:

 Given the cart has two products in When I empty the cart Then I should see it has nothing in it. 

This can be exactly the same as the actual shopping cart as a user interface. There are no implementation details in it. You can see that some of the steps correspond to several of yours; this is good, since it preserves the complexity of the code, where it is more convenient to maintain.

If we describe your other scenario this way, we get:

 Given my cart is empty Then I should not be able to empty it again. 

There is no "when" because "then" is simply true for this state.

Do you really need this script? Will you be able to kill you or your company by releasing with the possibility of emptying an already empty basket? It is essentially aesthetically pleasing. It has been added to simplify the use of the user interface, and the only way to find out if the user interface can be used is to actually use it. If you ever find such scenarios, I recommend taking them out. You can always do a modular logic check, which turns a button on or off.

If you switch to this style of language, delete all scripts that test only aesthetics and usability, you will find that your function files become much smaller.

I also recommend putting the most interesting or unexpected scenarios at the top. For example, this would be a more interesting scenario (and yes, it has two “when” in it, because it describes the behavior associated with the interaction between two different users):

 Given a user put a copy of "Moby Dick" in his cart When the last copy of "Moby Dick" is sold And the user comes back to look at his cart Then it should tell him, "Sorry, this item is currently out of stock." 

That would be even more interesting:

 Given a user put a new copy of "Moby Dick" in his cart And there are second-hand copies of "Moby Dick" available When the last new copy of "Moby Dick" is sold And the user comes back to look at his cart Then it should tell him, "Sorry, this item is currently out of stock." And it should also show the way to the second-hand copies with, "2nd hand copies are available." 

This will be a differentiating scenario; what your store did differently in other stores and, therefore, was of great interest to the business.

By placing the most interesting at the top of the page, it does not matter that the function file is long. We all know how the basket for buying and selling items works, and we still don't read the scripts below at this point.

Andy Waite is right when he says there are no hard and fast rules, so play by ear; if it does not work, do something differently. Hope these tips also help.

+9
source

You can group functions into folders, for example. you can have a cart folder and then function files for emtpy_cart.feature , update_cart.feature , etc.

There are no strict rules, but personally I would not put more than 8 scripts in one function file.

Check out Get distracted by your docs for a great example of how to structure functions: https://www.relishapp.com/relish/relish

+2
source

All Articles