it:ad:specflow:howto:write_a_scenario

IT:AD:SpecFlow:HowTo:Write A Scenario

Anyone can write a feature (BA, Client, Tester, Dev). They're simple enough in structure and language (English) that they can be understood by all on the team, without ambiguity.

Feature: Search For Famous People
    Blah...

@mytag
Scenario: A successful test for a well known User
    Given A First name of "Kirk"
    And a last name of "Douglas"
    When I press Search
    Then I should get back a list of one or more hits.
    

Scenario: A successful test for some well known names
    Given The following first and last names:
        | First  | Last  |
        | Bugs   | Bunny |
        | Betty  | Page  |
        | Sophie | Loren |
    When I press Search
    Then I should get back a list of more than one hits.

Scenario: An unsuccessful test for some well known names
    Given The following first and last names:
        | First  | Last    |
        | Sky    | Sigal   |
        | Ali    | Kazoom  |
        | Hans   | Nobody  |
    When I press Search
    Then I should get back a list of with zero entries.

If you are using NUnit and not MSTest (ie a Unit Test framework that supports RowTest), you can run multiple tests in one go, feeding it varied data:

Scenario Outline: My Scenario 
Given I enter <first>
And enter <last>
When when I press Go
Then I should get <result>

Examples:
| first | last | result |
| 1     | 4    | 5      |
| 3     | 4    | 7      |

Feature File Elements

Each File describes a single Feature, and then descrives n+ Scenario's of the use of that feature.

  • Feature:
    • Has – on the same line – a title and
      • a free-form high level (indented) description of the Feature, below the title.
      • Best practice:
        • Keep it short (a reader has to remember it as they read each scenario…)

      * Background:

    • Using Given+And syntax, can be used to setup test conditions before each and every of the scenarios.
  • Scenario:
    • has – on the same line – a scenario name/title.
    • Best practice:
      • Keep them short (complicated scenarios hint at overly-complicated processes)

    * Given/When/Then:

    • Under Scenario, one has the Given+And/When/Then structure.
  • @tag:
    • Used for categorization mainly (maps to the UnitTest category).
      • Where one can type them Requirements for Traceability.
    • But can be used to apply custom logic to the feature Scenarios.
    • Apply to a Scenario, or on a feature to apply them to all Scenarios in the feature file.
    • Can apply more than one, all on one line, separated by spaces.
    • @ignore any tests you want to ignore.
  • Comments
    • Comments are not proper syntax, but if you have to use then, prefix the line with #
  • /home/skysigal/public_html/data/pages/it/ad/specflow/howto/write_a_scenario.txt
  • Last modified: 2023/11/04 01:57
  • by 127.0.0.1