Search code examples
testingbddcomputation-theory

BDD Feature & Scenario


i am currenty studying BDD, but i have a different doubt, can you tell me if the following is right or not:

  • 1) Feature = it means "the problem" isn't it?
  • 2) Scenario = the way (the beahaviour) to resolve the feature

I find very difficult to find the "given when then" sentences. In this problem for example:

As a student

I would like / i want to calculate the rectangle perimeters if i have 2 number Or the circle area if i have one

So i don't make mistake with the computation

I wrote down the scenario, is that correct?

Given 1 number

Or 2 number

When i have 1 positive number

Or 2 positive number

Then calculate the area

Or the Perimeters


Solution

  • About the terminology:

    1) feature is not a "problem". It would rather be a solution. In software programming, a feature is a something that your program does to solve a problem. A feature could be the ability to compute the area of a rectangle.

    2) a scenario is a description of the usage of your feature. Like an example. Like a test case, but usually in a more human-readable form.

    3) a story (in Agile terminology, in which BDD stands) is a way to describe the a need/problem. Your problem ("as a student...") is presented as a story. This story will lead to a new feature in your soft. This new feature will be tested by scenarios.

    About your scenarios.
    Yours are not correct.
    There is no way to know that if you have 1 nb you should compute an area.
    You should have several scenarios, like

    Given I send the number 2 
    When I launch the computation
    Then I get the result 12,56
    
    Given I send the number 2 and 3
    When I launch the computation
    Then I get the result 10
    
    Given I send the number -4
    When I launch the computation
    Then I get the result error
    
    Given I send the number 1  3  7
    When I launch the computation
    Then I get the result error