Organizing cucumber test Scenarios and Features

Viewed 196

when a new client is added I want to verify if the newly added client's details are correct.

For example,

Create a new client, after creation search his name and check if the details are correct or not. Should I include them both in the same feature, or should I create a different feature for both adding and searching clients

Feature: Creating a new Client

    The user is
    Able to add a new Client

    Scenario: Valid client entry.The client has a username,address
        Given User is on the client page
        When When he clicks on the add new client
        Then He should see a pop up
        Then He will enter the client name,address,title,phone no and email
        And Click on the save button
Feature: Search for our newly added user

    The user will be able to search a client  
    
    Scenario: Search for our newly added client 
        Given  User is on the client page
        When   He click on the client search
        And Types the user name
        Then He should be able to match the first result
        When He clicks on the first matched result
        Then It will take him to a page with users details

 
2 Answers

It would be better to keep them separate. The strategy that worked best for me in many projects are, you should map each feature to the requirement (i.e. the high level user story or the requirement that is given to you from which you derive BDD scenarios and steps). Keeping each high level requirements in a separate feature files increases readability and maintainability.

In this case, looks like "Creating a new client" and "Search for our newly added client" are two different requirements/user stories, it is better to manage them separately, as the scenarios in each of these cases would vary. For an example, "Creating a new client" might have following scenarios:

Scenario 1: Create a valid client entry.The client has a username,address Scenario 2: Creating a valid client entry failed due to missing information Scenario 3: Creating a valid client entry failed due to client already exists

And for "Search for our newly added client" you would have other scenarios like: Scenario 1: Search for a newly added user using username and search result should show the user details Scenario 2: Search for a user using username who is not in the database and empty search result should be shown Scenario 3: Search for a newly added user using address details and search result should show the user details Scenario 4: Search for a user using username using address details who is not in the database and empty search result should be shown

As you can see, each feature is now nicely segregated and have their own related scenarios. As the project grows these scenarios are likely to grow and it would be easier to manage by keeping each high level requirements in a separate feature file.

Also another practice that really worked well for me is to prefix the Jira ticket(or whichever tool you use to manage your user stories) to the feature file as it would be easy to search and manage. For an example, your feature should be like "TI1001 - Creating a new Client" and "TI1002 - Search for our newly added user"

There are lots of ways to do this

features
  clients
    add_new_client
    search_for_clients

I'd favour this one if clients are a really significant part of the project

features
  client_add
  client_search

but this one would work.

The important thing is to try and be consistent.

As for your scenarios try and make them simpler e.g.

Feature: Add new clients

Background:
  Given I am allowed to add clients

Scenario: Add a client 
  Given there are no clients
  When I add a client
  Then there should be a client

You want your happy path scenarios to be this simple, so you can expand on them with sad paths. e.g.

Scenario: Add a new client without an address
  Given there are no clients
  When I add a client with no address
  Then I should see that a client cannot be added without an address

As far as searching goes things can get quite complex so again start simple

Feature: Search for clients

Scenario: Search for client Fred
  Given there is a client Fred
  When I search clients for Fred
  Then I should see client Fred

Scenario: Search for client Fred when Fred does not exist
  Given there is a client Sue
  And there is not a client Fred
  When I search for Fred
  Then I should see a not found result

Scenario: Search for clients by postcode
Scenario: ...

With searching you need to be careful not to spend all your time testing your search engine (it should already be well tested.

These sort of features and scenarios are declarative, rather than imperative. They state WHAT they are doing and WHY, but avoid describing HOW anything is done. Cuking is much more effective with a declarative approach.

Related